//这里的代码适当修改是可以用来清理缓冲区的
int main() {
int ch = 0;
while ((ch = getchar()) != EOF)
{
putchar(ch);
}
return 0;
}
int main() {
//举一个例子
//假设密码是一个字符串
char password[20] = { 0 };
printf("请输入密码:>");
scanf("%s", password);
//getchar();//读取/n
int ch = 0;
while ((ch = getchar()) != '\n')
{
;
}
printf("请确认密码(Y/N):>");
int ret = getchar();
if (ret == 'Y')
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
}
//只打印数字字符
int main() {
char ch = '\0';
while ((ch = getchar()) != EOF) {
if (ch < '0' || ch>'9')
continue;
putchar(ch);
return 0;
}
}
标签:ch,return,int,C语言,printf,main,getchar
From: https://blog.csdn.net/A5437942/article/details/137029383