-1
我需要使用strtok函数来分析某些字符串中的每个单词。 我写了这样的代码:在函数strtok()中奋斗C
char *token;
token=strtok(string,symbol);
while(token!=NULL){
functionX(token); //this is a function that anlayze the token
token=strtok(NULL,symbol);
}
但“functionX”只接收字符串和空指针的第一句话即可。 如果我把
printf("%s",token);
,而不是functionX它打印每一块字符串。 我该如何解决这个问题?
这就是我所谓的 “functionX”:
void match(char *token, char *code){
FILE *rules;
char *tmp_token;
char stream[15];
int found;
rules=fopen("rules.vk","r");
found=0;
while((fgets(stream,sizeof(stream),rules))>0){
tmp_token=strtok(stream,";");
if((strcmp(tmp_token,token))==0){
strcpy(code,strtok(NULL,";"));
found=1;
}
}
if(found==0) strcpy(code,token);
}
可以显示“functionX”功能码? –
@MohdShahril Yup。 这是一个根据文件中写入的一些规则将每个标记与翻译关联的函数。 即: pastebin.com/rBKi1Bx0 – NosPix
请发布最小版本的'functionX',它在问题*中显示错误*。添加评论链接是没有用的 - 当它是无效链接时更是如此。 –