一个字符串夹杂其他特殊字符,需要从其中找出有用数据
#include <stdio.h>
#include <stdlib.h>
void getword(char *word, char *line, char stop)//123&4456
{
int x =0, y = 0;
for(x=0;((line[x]) && (line[x] != stop)); x++)
word[x] = line[x];
word[x] = '\0';
/*
if(line[x])
++x;
while(line[y++] = line[x++]);
*/
}
int main()
{
char *c1="123123&345345";
char t1[100];
int num=0;
printf("num=%d",num);
getword( t1,c1,'&');
num=strtol(t1,NULL,10);
printf("num=%d",num);
return 0;
}
输出
: