sscanf()函数内容匹配输出
30 license(s) used by root@aifserver [10.109.40.53]
用sscanf()函数进行匹配,输出内容为
30
root
aifserver
10.109.40.53
[解决办法]
#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还有区别吗