Chapter - 13: File Input-Output

What is the purpose of the library function fflush( )?


When we get any character from the keyboard, so this procedure takes place.

- We enter a character from the keyboard.

- Characters entered are go in Standard Input Stream

- function like scanf() or getch() fetch that character from the Standard Input Stream, and not from the keyboard.

So, hitting Enter key after the character key, store Enter also in Standard Input Stream, so the next function scanf() or getch(), do not wait to get a character from the keyboard, but take the Enter key, hit previously from the Standard Input Stream. So, to solve this problem we have to clear our buffer completely before functions scanf("%c") or getch(). This function is performed by fflush(stdin).

© 2021 Garbage Valuegarbage value logo