在C / C ++中清除输入缓冲区
函数fflush(stdin)用于刷新或清除流的输出缓冲区。在scanf()之后使用它时,它也会刷新输入缓冲区。如果成功,则返回零,否则返回EOF并设置feof错误指示符。
这是fflush(stdin)的语法,用于清除C语言的输入缓冲区,
int fflush(FILE *stream);
这是fflush(stdin)清除C语言输入缓冲区的示例,
示例
#include <stdio.h>
#include<stdlib.h>
int main() {
char s[20];
printf("Enter the string : \n", s);
scanf("%s\n", s);
printf("The entered string : %s", s);
fflush(stdin);
return 0;
}输出结果
这是输出
Enter the string : helloworld The entered string : helloworld
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短