当前位置: 技术问答>linux和unix
how to use sscanf?
来源: 互联网 发布时间:2014-10-31
本文导语: s_str: |fjdkfjd||fjkdfjdk| how to sscanf this string? do you know? sscanf(s_str,"|%[^|]|%[^|]|%[^|]|", s_str1, s_str2, s_str3); it doesn't work because the s_str2 cannot get. anybody know how to do that ? | 这种情况恐怕sscanf...
s_str: |fjdkfjd||fjkdfjdk|
how to sscanf this string? do you know?
sscanf(s_str,"|%[^|]|%[^|]|%[^|]|", s_str1, s_str2, s_str3);
it doesn't work because the s_str2 cannot get.
anybody know how to do that ?
how to sscanf this string? do you know?
sscanf(s_str,"|%[^|]|%[^|]|%[^|]|", s_str1, s_str2, s_str3);
it doesn't work because the s_str2 cannot get.
anybody know how to do that ?
|
这种情况恐怕sscanf和strtok都不好用,不妨自己处理:
char s[]="|fjdkfjd||fjkdfjdk|";
char *ss[5];
char *p=s;
for(int i=0; *p;i++){
while(*p!='|')
++p;
*p='';
ss[i]=(++p);
}
ss[0],ss[1],ss[2]就是想要的结果
char s[]="|fjdkfjd||fjkdfjdk|";
char *ss[5];
char *p=s;
for(int i=0; *p;i++){
while(*p!='|')
++p;
*p='';
ss[i]=(++p);
}
ss[0],ss[1],ss[2]就是想要的结果