telegram.im/CProgrammingByPritamPaul follow this telegram channel for more recent updates and discussions on C Programming and Problem Solving Through C
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Shouldn't it be mentioned that it is undefined behavior according to C standard if you use if for stdin. Also, it's not portable and compiler specific. Visual studio code allows this.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
small hack if you dont like fflush function use space in scanf after " scanf("%c",&a) //cause input stream problem scanf(" %c",&s) // space that you use is solve your buffer problem Because someone times fflush create a bug that will ruin days to find thet what wrong with my code
@Rahul Kumar what if we are using gets function instead of scanf beacuse there we don't use %s And I have also tried to do using scanf instead of gets and also give a space after scanf But still I get the same problem Scanf(" %d", &b.bookid); Scan(" %s", &b.title) As you can see I have applied space in both scanf But still compiler not taking my string
@@someone-x64 we press the enter key after giving the first input if we do not place blank space before %c then, return character will be stored in the character variable ch. so, whitespace character is used to skip certain input.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream. Use the method explained here or "while(getc(stdin)! =/n) ;" instead
Welcome bro.. Please do support the channel .... so that i could make many more videos.... and please let me know if there is any doubt so i would try to make a video on that issue
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Hi sir...I got it...but can you explain me one thing?? If I read a file using getc...is there still buffer ?? Because I used fflush(stdin)when reading file's content via fgetc...fflush(stdin)is not working in this case...is the buffer used in fgetc... different with the buffer...which is used to store data which is coming from the external input device? Please say sir...this question is killing me
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
why it again take input for same character if we write "%c " in scanf "%c" pe it does not take input after pressing enter What is the role of space here??
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Because the first time it grabbed the first character in stdin but left the from the enter key in stdin. After" scanf.. " you should always write" while(getc(stdin)! = ) ;" to clear stdin.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Because the " " from pressing enter after the int stays stored in stdin and when you call scanf on a not empty instream the contents is returned instead of asking for user input. Scanf was not designed for user input.
@@danielhall6888 it's an old c function to interpret the stdin buffer. And it's just that a way to interpret stdin. It can be used to read input from the user. But it has some bad side effects of how it works internally.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
First of all: you explained it very well thank you for that! I understood everything. but secondly: i have a problem. i tried it and did exactly this example that you did. But for me it didn't work :( i must have done something wrong but i cant find where the problem is this is what i typed in: #include #include int main(){ int a; char ch; printf(" Enter any integer:"); scanf("%d", &a); fflush(stdin); printf(" Enter any character:"); scanf("%c", &ch); printf(" The integer is: %d ", a); printf("The character is: %c ", ch); return 0; } Did I do something wrong?
the code you have written here i have checked for it! and the code is showing the correct output. if you have telegram then text me there! @i_am_pritam_paul this is the ID ...
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Welcome bro.. Please do support the channel .... so that i could make many more videos.... and please let me know if there is any doubt so i would try to make a video on that issue
Why it still crashes here #include #include void cargarid(){ int f; int numclientes; printf("Cuantos clientes deseas agregar : "); scanf( "%d", &numclientes ); fflush(stdin); for(f=0;f
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
@@PRITAMPAUL Sir in a book, i saw that it has used a loop to clear the flush..it was done like this int dh; while((dh = getchar()) != ' ') ; this was stated as an alternative to fflush(stdin)...but i can't get it...can you please explain it
Yeah at that time my english was too bad. I was practicing and now after all the time I don’t think it is that much bad!! But thanks for the comment. And those who are laughing on this are the most stupid and negative people ever any creator can have. They come here to judge on english or to get some knowledge i dont know.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
telegram.im/CProgrammingByPritamPaul
follow this telegram channel for more recent updates and discussions on C Programming and Problem Solving Through C
You can also use scanf("
%c",ch) or scanf(" %c",ch) (space before %c) to remove buffer from the keyboard instead of fflush(stdin)
thanks bro
yes
thanks
This Video Lecture is so helpful for me.... Thanks a lot sir
How about 'fflush(stdout)'?
Awesome video. Was in a problem for the last 3 hours. Crystal clear video. Thank you. Make more videos like this
Glad it helped
Awesome.
Quick & easy without any need for unorthodox tricks or hack work-arounds.
Enjoyable.
Thank you for this explanation sir👍
most welcome
please do visit other playlists also
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Thank you so much sir. It's very useful..and you have expalined it so well..😃😃😃
You wellcome!
do follow the other playlists! and subscribe the telegram channel too for more recent updates
Tqs Sir your explained process is very good!😊
Is in c++ also need to buffer flush when we working with cin (string) ?
thank you so much! you explained it very well!!
You wellcome!
do follow the other playlists! and subscribe the telegram channel too for more recent updates
THANK YOU SO MUCH, Very helpful video
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Shouldn't it be mentioned that it is undefined behavior according to C standard if you use if for stdin. Also, it's not portable and compiler specific. Visual studio code allows this.
Yes, fflush(stdin) is undefined behavior. fflush is meant to be called on an output stream (i.e. fflush(stdout))
Keep doing, nice explanation
far better than those who just put the definition in video.
Thanks a lot 😊
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Thank you! A great explanation.
excelent video! the best I've seen
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Thank you sir.
Most welcome
Share these videos if you found them useful... your support would encourage me to make more videos
small hack if you dont like fflush function use space in scanf after "
scanf("%c",&a) //cause input stream problem
scanf(" %c",&s) // space that you use is solve your buffer problem
Because someone times fflush create a bug that will ruin days to find thet what wrong with my code
space works. Thank you for that.
i have not found fflush(stdin) creating any bug. so need to explore more...
thanks for the comment bro
@Rahul Kumar what if we are using gets function instead of scanf beacuse there we don't use %s
And I have also tried to do using scanf instead of gets and also give a space after scanf
But still I get the same problem
Scanf(" %d", &b.bookid);
Scan(" %s", &b.title)
As you can see I have applied space in both scanf
But still compiler not taking my string
Fflush cleans all the privous data from the buffer or just the input which is given before fflush(mean here fflush cleans only enter or 3 also)?
only the enter.. the last input
Thank you very much.....it's helped me lot....
my pleasure 🥰
@@PRITAMPAUL can you give ur phone number?
I have a question.......
Instead of using that method,
We can simply write ,
scanf(“ %c”,&ch);
//space is given before %c
What does it do? Can you elaborate it 🙄
@@someone-x64 we press the enter key after giving the first input if we do not place blank space before %c then, return character will be stored in the character variable ch.
so, whitespace character is used to skip certain input.
@@ipsakarki4442 does whitespace and enter means the same?
Nice
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Use the method explained here or "while(getc(stdin)! =/n) ;" instead
thank for video....its helpful
You are most welcome...
Please like the video and share with your friend and subscribe the channel for more
Sir while usingf fflush in ourn program why character is taking enter but int b is not taking enter
due to the input buffer!
Great Work Brother
thank u.... please visit other playlists also
Thank You so much, that was a clean explanation :-)),
Welcome bro.. Please do support the channel .... so that i could make many more videos.... and please let me know if there is any doubt so i would try to make a video on that issue
Thanks exactly looking for this.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Sir which IDE you were using in this video???
DEV C++
You can download this from net! in the following link you would find the way to download the IDE
th-cam.com/video/jmvuIEhaKTs/w-d-xo.html
Hi sir...I got it...but can you explain me one thing??
If I read a file using getc...is there still buffer ??
Because I used fflush(stdin)when reading file's content via fgetc...fflush(stdin)is not working in this case...is the buffer used in fgetc... different with the buffer...which is used to store data which is coming from the external input device?
Please say sir...this question is killing me
Don't use fflush everywhere it's result is unpredictable...try to avoid using it...
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Is stdin and fflush are same?
why it again take input for same character if we write "%c " in scanf
"%c" pe it does not take input after pressing enter
What is the role of space here??
I didn't get your question. Please elaborate it again.
Thank You
do not use fflush(stdin) as it has an undefined behavior in ISO C, POSIX ....
Thanks sir its my dout will be cleared
Amazing sir.
So nice of you
Thank You
Thank you Brother
What is stdin you wrote
Standard input device
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
thanks sir, well noted.
u welcome.. if you found this useful please do like, share and subscribe the channel for more videos.
Sir what is buffer please explain it
Sure later in any video i will disscuss
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
A buffer in general is an intermediate storage for something. In this case for characters coming from the input you typed in.
it is very helpful video data
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Well explained...
Thank You.. Please Do subscribe for more videos in near future
Thank you sir
What about fflush(stdout) ? Does it have the same use such as fflush(stdin) or what is exactly the difference?
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Flush stdout clears stuck characters that weren't printed after pushing them to the buffer. It is a legitimate use of fflush.
OKAY :)
Thank you very much...
You're most welcome
Sir my professor many times mention that use newline (whenever using printf) to flush buffer what is that exactly?
Nice video 🥰
Keep watching
Fflush(stdin) is use in c++ or not??
yes! you can use it.
please go through the link for more detailed explanation
www.programiz.com/cpp-programming/library-function/cstdio/fflush
What's this at one time you says that enter is also a character, if it is!! than why at first time it shows character
Didn't get your question! Please do elaborate again. Thank You
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Because the first time it grabbed the first character in stdin but left the
from the enter key in stdin. After" scanf.. " you should always write" while(getc(stdin)! =
) ;" to clear stdin.
Nice explanation
thanks brother.
Please do subscribe and do support the channel ... and please do visit other playlists also
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Thanks a lot bro.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Thankyou brother
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Thank you
welcome
Nice videoo
You are most welcome...
Please like the video and share with your friend and subscribe the channel for more..
please do check other playlist also
thank you so much buddy
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
I have a doubt that why this problem of buffer doesn't happen in integer or float
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Because the "
" from pressing enter after the int stays stored in stdin and when you call scanf on a not empty instream the contents is returned instead of asking for user input. Scanf was not designed for user input.
@@redcrafterlppa303 What was the original purpose behind scanf?
@@danielhall6888 it's an old c function to interpret the stdin buffer. And it's just that a way to interpret stdin. It can be used to read input from the user. But it has some bad side effects of how it works internally.
@@redcrafterlppa303 but I believe he is talking about C not C++?
thank you...........................
You are most welcome...
Please like the video and share with your friend and subscribe the channel for more..
please do check other playlists also
doubt sir. Why doesn't 3 "input number" get cleaned from the inputs? What all characters will get cleaned except "ENTER", that is some other examples.
I didn't get your Question! Please tell me elaborately
You Can text me on Telegram @i_am_pritam_paul
@@PRITAMPAUL I texted you
on telegram
@@Rahul-zo2rz replied you also
Thnks sir
Welcome
please do like, share and subscribe for more
and check other playlists also
Thanks man 🙏
Happy to help
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Is fpurge same?
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Fpurge seems like it's actually designed to clear an instream. But if you want to be sure use "while(getc(stdin)! =
) ;"
thanks brother.
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
thanks okay?
sorry?
First of all: you explained it very well thank you for that! I understood everything.
but secondly: i have a problem. i tried it and did exactly this example that you did. But for me it didn't work :( i must have done something wrong but i cant find where the problem is
this is what i typed in:
#include
#include
int main(){
int a;
char ch;
printf("
Enter any integer:");
scanf("%d", &a);
fflush(stdin);
printf("
Enter any character:");
scanf("%c", &ch);
printf("
The integer is: %d
", a);
printf("The character is: %c
", ch);
return 0;
}
Did I do something wrong?
Hii.. first of all thanks for watching my video. And also thanks for comment.
Can I get to know which OS and which compiler are you using?
the code you have written here i have checked for it! and the code is showing the correct output.
if you have telegram then text me there!
@i_am_pritam_paul
this is the ID
...
Thx brother this was troubling me for two days
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
what is fflush(stdout)
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Undefined behavior.
Amazing explanation 🔥
Thank you 🙌
please do support the channel so that i could make many more videos like this
Sir please explain digramticaly
bhaiya thanku
Welcome bro.. Please do support the channel .... so that i could make many more videos.... and please let me know if there is any doubt so i would try to make a video on that issue
Why it still crashes here
#include
#include
void cargarid(){
int f;
int numclientes;
printf("Cuantos clientes deseas agregar : ");
scanf( "%d", &numclientes );
fflush(stdin);
for(f=0;f
Which one is crashed?
if you use the getchar function you will see the same thing.
getchar() is used to hold the output screen untill you press any character in keyboard!
it still skips for me!
send me your code in telegram
@i_am_pritam_paul
Ohmaygad
💀💀💀
#PritamPaul
#prp
#CProgrammingbyPritamPaul
Ok
Awesome explanation.
Thanks
please do subscribe and support the channel
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
Thanks for this video.
You are most welcome...
Please like the video and share with your friend and subscribe the channel for more..
please do check other playlists also
dude your voice , is causing me a headache
sry at that time my audio system was not so good! in recent videos i hope you won't face this kind of issue
You should never use fflush(stdin) ever the behaviour is undefined. But the problem presented does have other solutions
1. I have shown where fflush(stdin) could be used! have not discussed either it should be used or not.
2. ya it has other solutions too
bdw thanks for commenting! really helpful and motivating
@@PRITAMPAUL your welcome.
@@PRITAMPAUL Sir in a book, i saw that it has used a loop to clear the flush..it was done like this
int dh;
while((dh = getchar()) != '
')
;
this was stated as an alternative to fflush(stdin)...but i can't get it...can you please explain it
@@gautamchaudhary3325 it means that the while loop will be going on until you press enter in your keyboard
hindi bol le ise badiya toh
🤣🤣🤣🤣
Yeah at that time my english was too bad. I was practicing and now after all the time I don’t think it is that much bad!! But thanks for the comment.
And those who are laughing on this are the most stupid and negative people ever any creator can have.
They come here to judge on english or to get some knowledge i dont know.
Hindi mein bol lete vai
😅 I have more proficiency in English than Hindi. I am not from hindi medium brother. I am a bengali guy
@@PRITAMPAUL বুঝলাম, ঠিক আছে same আমারও
Thank you sir
Thanks
Well explanation sir
thank u
please do subscribe to support the channel & visit other playlists as well
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
thank you
Please don't use fflush on an instream like stdin. It's undefined behavior and is compiler specific. It is not part of the c++ standard to flush an instream.
@@redcrafterlppa303 scanf("
%c",ch) so this is more advisable?