ฟังก์ชัน 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