一个提取字符串的问题
在数组存放一大串的字符,我想提取一些内容,格式
afsadf...(
This is my wanted
192.168.1.100
192.168.1.200
end of server
adfasdf
...
我想提取this is my wanted和end of server之间的数据,如何实现? 正则或其他
[解决办法]
#include <stdio.h>
#include <string.h>
char s[]="afsadf...("
"This is my wanted "
"192.168.1.100 "
"192.168.1.200 "
"end of server "
"adfasdf"
"...";
char *p;
char ip[16];
int n;
int main() {
p=strstr(s,"This is my wanted ");
if (p) {
p+=18;
while (1) {
if (1==sscanf(p,"%15[0-9.]%n",ip,&n)) {
printf("[%s]\n",ip);
p+=n+1;
} else break;
}
}
return 0;
}
//[192.168.1.100]
//[192.168.1.200]
//