是否要继续(y / n)在此c代码中不起作用。我希望它在我输入'y'时输入一个字符串,如果输入n,则退出程序。我尝试了很多选择,但无济于事。 谢谢你的帮助
do
{
i = 0, final = 0, s = 0;
printf("\n\nEnter Input String.. ");
scanf("%s", string);
while (string[i] != '\0')
if ((s = check(string[i++], s)) < 0)
break;
for (i = 0 ; i < nfinals ; i++)
if (f[i] == s )
final = 1;
if (final == 1)
printf("\n String is accepted");
else
printf("String is rejected");
printf("\nDo you want to continue.? \n(y/n) ");
}
while (getch() == 'y');
return getch();
}
答案 0 :(得分:0)
if (getch() == 'n') {
// print something
return;
}
答案 1 :(得分:0)
在将char作为输入之前应该刷新缓冲区
do
{//..your code
printf("\nDo you want to continue.? \n(y/n) ");
scanf("%c",&ch);
scanf("%c",&ch);
}
while (ch == 'y');