Question : how to clear standard input buffer in C
Answered by : necati-ergin
int c;
while ((c = getchar()) != '\n' && c != EOF) ; //null statement
Source : | Last Update : Thu, 26 May 22
Question : clear buffer in c
Answered by : bewildered-bee-1gdc72vqpriq
while (getchar() != '\n');//Clearing the buffer
Source : | Last Update : Fri, 15 Apr 22
Question : Clearing The Input Buffer In C/C++
Answered by : travinth-dayalaeaswaran
// C Code to explain why not
// clearing the input buffer
// causes undesired outputs
#include<stdio.h>
int main()
{
char str[80], ch;
// Scan input from user -
// GeeksforGeeks for example
scanf("%s", str);
// Scan character from user-
// 'a' for example
ch = getchar();
// Printing character array,
// prints “GeeksforGeeks”)
printf("%s\n", str);
// This does not print
// character 'a'
printf("%c", ch);
return 0;
}
Source : https://www.geeksforgeeks.org/clearing-the-input-buffer-in-cc/?ref=lbp | Last Update : Fri, 15 Jul 22