清空 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
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP