#MystricalConcepts1 - Use of fflush() in C Language .
Anupravi Garg
Learner | Software Engineer | Winner @SIH | Content Writer | Video Creator | Front End Developer
Have you ever used fflush() in c ?
If not yet , then you are at a perfect place to learn about it in a easy way.
Task - when you want to take two inputs one integer and one character
Problem Faced - During output after entering first input i.e. integer value, the output gets printed and you are not able to enter the second input i.e. character Value.
Like, Have you ever encounter such issue while coding in C.
As shown in Code Snippet given below:
Reason - Whenever we store a value into a variable it first gets stored in a buffer called INPUT BUFFER before getting stored to the actual variable i.e. Memory Location, And as We have only a single INPUT BUFFER so as we press enter button after entering 1st value, the value of "enter key" gets stored in the INPUT BUFFER as 2nd Input value, so to get the second input i.e. Character Value, we need to first Clear the INPUT BUFFER.
Solution - To Solve this Problem fflush() came into picture.
fflush() - It is used to clear the buffer..
Syntax - fflush(stdlin);
Now Here, we will use fflush() after getting the first input i.e. integer value to clear the buffer, and then we can easily get the second input i.e. character value.
As shown in Code Snippet given below:
This technique, using fflush(), elegantly addresses input buffer challenges, ensuring a seamless user experience in C programming.
.
.
If you find value in this content, kindly consider sharing it with your Friends. Your support is greatly appreciated, and it helps foster a community of knowledge-sharing.
.
.
Follow me Anupravi Garg for more such content.
Thank you??