#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
int main()
{
char str1[128] = {0};
FILE *fp;
char str2[128] = {0};
char str3[128] = {0};
int num = 128;
fp = fopen("test","r");
if(fp < 0)
{
printf("the fp open error\n");
}
//fscanf(fp,"%s",str1);
fscanf(fp,"%[^,],%s",str2,str3);
fclose(fp);
//num = strncmp(str2,"LTE,0",5);
//printf("the str2 is %s and num is :%d\n",str2,num);
//sscanf(str1,"%[^,],%s",str2,str3);
printf("the str2 is %s and str3 is %s\n",str2,str3);
char buf[128] = "aaa,bbb,ccc,ddd";
char buf1[32] = {0};
char buf2[32] = {0};
char buf3[32] = {0};
char buf4[32] = {0};
sscanf(buf,"%[^,],%[^,],%[^,],%s",buf1,buf2,buf3,buf4);
printf("the buf1 : %s\nthe buf2 : %s\nthe buf3 : %s\nthe buf4 :%s\n",buf1,buf2,buf3,buf4);
return 0;
}
函数编译运行:
tips:
%*[^,]:的写法,可以将这一逗号分割的字符省略