Is there any way to flush the input buffer? The problem where I faced it will make it clear what I want exactly.
Code:
main(){
char buffer[20];
scanf(“%s”, buffer);
getchar();
}
Since the scanf does not take in the newline when the enter key is pressed, it remains in the buffer which is taken by getchar(); thus it does not wait for user input anymore. Of course this problem can be solved by replacing scanf with functions such as gets() or similar function as follows:-
Code:
main(){
char buffer[20];
gets(buffer);
getchar();
}
But I want to know if there is any way to flush the input buffer. fflush () works for output stream not input; aren’t there any equivalent function for input stream?