首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

sscanf()函数内容婚配输出

2012-10-17 
sscanf()函数内容匹配输出30 license(s) used by root@aifserver [10.109.40.53]用sscanf()函数进行匹配,

sscanf()函数内容匹配输出
30 license(s) used by root@aifserver [10.109.40.53]
用sscanf()函数进行匹配,输出内容为

30
root
aifserver
10.109.40.53

[解决办法]

C/C++ code
#include <stdio.h>#include <string.h>int main(){    char buf[20]={0};    char buf1[20]={0};    char buf2[20]={0};    char buf3[20]={0};    char buf4[20]={0};    sscanf("30 license(s) used by root@aifserver [10.109.40.53]","%[^ ] %*[^ ] %*[^ ] %*[^ ] %[^@]@%[^ ] [%[^]]",buf,buf1,buf2,buf3,buf4);    printf("%s\n%s\n%s\n%s\n%s\n",buf,buf1,buf2,buf3,buf4);    return 0;}
[解决办法]
匹配英文字符可以用 %[a-zA-Z]
匹配IP地址可以用 %[0-9.]

修改源字符串 在读取数据不可取 
统一用 %[^ ] 把强大的[]用渣了 这个和 %s还有区别吗

热点排行