我的代碼有問題。我需要在c中使用strtok()在字符串「Date WEEk Dae Due Toy De Dae i Date Due」中輸出單詞「Sing」和「Toy」(它們都在「Due」和「De」之間)唱德「。我試圖使用代碼中的if語句明確地輸出單詞「Sing」和「Toy」,但是我的代碼不會產生任何輸出,並且在編譯期間沒有警告。我只是C的初學者,請耐心等待。我聽說像strstr()這樣的其他函數可能能夠完成與strtok()相同的工作,所以如果其他函數使用起來更加方便,請不要猶豫,使用這些函數。謝謝。 摘要:我試圖在上面的字符串中使用strtok()來獲取「Due」和「De」之間的單詞,並且可以這樣做,還是應該使用另一個函數?如何使用strtok得到一個詞
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char string[]="Date WEEk Dae Due Toy De Dae i Date Due Sing De";
char*pch;
pch=strtok(string,"De");
while(pch!=NULL){
if((*(pch-1)=='a')&&(*(pch-2)=='u'))
printf("%s\n",pch);
pch=strtok(NULL,"De");
}
return 0;
}
壓痕........................... – ThingyWotsit
什麼是'由於結果唱歌德? 「唱歌」還是「唱歌」或者這不適用? – BLUEPIXY