【发布时间】:2012-04-10 03:17:14
【问题描述】:
我在程序中创建了一个 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);
}
}
编辑:输入来自键盘。 编辑编辑:新代码(同样的问题)
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在初始循环迭代中最初有垃圾。
标签: c loops while-loop