-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',它在問題*中顯示錯誤*。添加評論鏈接是沒有用的 - 當它是無效鏈接時更是如此。 –