为什么不能用while ((tem = getchar()) != EOF)清除缓存,输入以后回车只能一直换行,跳不出循环
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
char ch[20];
printf("Please enter the password.");
scanf("%s", ch);
int tem;
while ((tem = getchar()) != EOF)//出错
;
printf("Please confirm the password Y/N");
char i = getchar();
if (i == 'Y')
{
printf("Success");
}
else
printf("Fail");
return 0;
}
运行结果
用这个却可以
while ((tem = getchar()) != '\n' && tem != EOF);
;