プログラム内でwhileループを作ってプログラムがwhileループに達しましたが、実行されません。私はずっと長い間コードを見てきたので、私が見逃している本当に小さなエラーがあるように感じます。whileループ実行中
int strbuf = 100;
char string[strbuf];
char *exit = "exit";
while(!strcmp(string, exit)){
printf("Enter a word to search. Enter exit to quit");
scanf("%s", string);
state = present(fIndex, string);
if(state){
printf("The word %s was found on line %d", string, state);
}
}
EDIT:キーボードからの入力です。 編集編集:NEW CODE(同じ問題)
int strbuf = 100;
char string[strbuf];
char *exit = "exit";
printf("Enter a word to search. Enter exit to quit\n");
scanf("%s", string);
while(!strcmp(string, exit)){
state = present(fIndex, string);
if(state){
printf("The word %s was found on line %d", string, state);
}
else printf("The word %s was not found", string);
}
whileループの前に入力を取るとは思いませんか? 'string'は最初のループの繰り返しでゴミを持っています。 – Mahesh