清空 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