#include <stdio.h>
int main(void)
{
char F,C;
printf("Do you have a Fever? y/n\n");
F = getchar();
printf("Do you have a runny nose or cough? y/n\n");
C = getchar();
printf("Here are the results you input:\n");
printf("Do you have a fever?");
putchar(F);
printf("\nDo you have a runny nose or cough?");
putchar(C);
return 0;
}
代码首先输入结果getchar();
,然后退出而无需等待更多输入。这是为什么?
如果只想处理一个字符,请while
在每个getchar()
字符后使用循环
printf("Do you have a Fever? y/n\n");
F = getchar();
while((F = getchar()) != EOF && F != '\n') // This will eat up all other characters
;
printf("Do you have a runny nose or cough? y/n\n");
C = getchar();
while((C = getchar()) != EOF && C != '\n')
;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句