字符串组合函数sprintf
sprintf(str, “%s%s”,str1,str2);
字符串分割函数sscanf和strtok
strtok是线程不安全函数,会使用静态内存(类似静态变量)
使用一个规定字符分割字符串,比如“,”
1 #include <stdio.h>
2 int main()
3 {
4 char a1[100] = {0};
5 char a2[100] = {0};
6 char* a = “ha hahahahah,wwwwwww”;
7 if(2 == sscanf(a, “%[^,],%s”,a1, a2))
8 {
9 printf(“cbf:%s\n”, a1);
10 printf(“cbf:%s\n”, a2);
11 }
12 }
结果:
cbf:ha hahahahah
cbf:wwwwwww
博客介绍了字符串组合函数sprintf,可将多个字符串组合。还介绍了字符串分割函数sscanf和strtok,其中strtok线程不安全,使用规定字符如逗号分割字符串,并给出了使用sscanf分割字符串的代码示例及结果。

1117

被折叠的 条评论
为什么被折叠?



