Re: [algogeeks] what is the use of fflush ?
Excerpt from The C Programming Language by Kerninghan Ritchie - *int fflush(FILE *stream) - *On an output stream, fflush causes any buffered but unwritten data to be written; *on an input stream, the effect is undefined*. So fflush was never meant for stdin. - Ravindra On Sun, Oct 9, 2011 at 10:09 PM, Hatta tmd...@gmail.com wrote: don't fflush(stdin) it doesn't make any sense. fflush(stdout) and fflush(stderr) only. On Sun, Oct 9, 2011 at 8:20 AM, Saravanan Selvamani saravananselvam...@gmail.com wrote: Hi, In the following programming when i gave character input rather than integer , the following scanf statement is not working . so i introduce the fflush(stdin) before the last scanf statement. But i get the same error as i before . #includestdio.h int main() { int a,b; scanf(%d,a); fflush(stdin); scanf(%d,b); printf(%d,b); //prints some garbage value. return 0; } so then what is the use of the fflush(stdin) and how to correct the above error? Thanks in advance. Regards P.S.Saravanan. -- why so serious? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Hatta -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] what is the use of fflush ?
Hi, In the following programming when i gave character input rather than integer , the following scanf statement is not working . so i introduce the fflush(stdin) before the last scanf statement. But i get the same error as i before . #includestdio.h int main() { int a,b; scanf(%d,a); fflush(stdin); scanf(%d,b); printf(%d,b); //prints some garbage value. return 0; } so then what is the use of the fflush(stdin) and how to correct the above error? Thanks in advance. Regards P.S.Saravanan. -- why so serious? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] what is the use of fflush ?
just take input a and b in one statement like this scanf(%d %d ,a ,b); On Sun, Oct 9, 2011 at 4:50 PM, Saravanan Selvamani saravananselvam...@gmail.com wrote: Hi, In the following programming when i gave character input rather than integer , the following scanf statement is not working . so i introduce the fflush(stdin) before the last scanf statement. But i get the same error as i before . #includestdio.h int main() { int a,b; scanf(%d,a); fflush(stdin); scanf(%d,b); printf(%d,b); //prints some garbage value. return 0; } so then what is the use of the fflush(stdin) and how to correct the above error? Thanks in advance. Regards P.S.Saravanan. -- why so serious? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] what is the use of fflush ?
After scanning the variable a, you will give a whitespace character(space,tab or newline), which will also get stored into stdin file. So next statement will scan this whitespace character. fflush(stdin) flushes(clears) the contents of stdin file, so this time scanf will not get whitespace character, instead it will get the character entered by user. or in second scanf statement, change it as scanf( %c,b), notice the space before %c. Correct me if m wrong :) Sanju :) On Sun, Oct 9, 2011 at 6:55 PM, rajul jain rajuljain...@gmail.com wrote: just take input a and b in one statement like this scanf(%d %d ,a ,b); On Sun, Oct 9, 2011 at 4:50 PM, Saravanan Selvamani saravananselvam...@gmail.com wrote: Hi, In the following programming when i gave character input rather than integer , the following scanf statement is not working . so i introduce the fflush(stdin) before the last scanf statement. But i get the same error as i before . #includestdio.h int main() { int a,b; scanf(%d,a); fflush(stdin); scanf(%d,b); printf(%d,b); //prints some garbage value. return 0; } so then what is the use of the fflush(stdin) and how to correct the above error? Thanks in advance. Regards P.S.Saravanan. -- why so serious? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] what is the use of fflush ?
Sorry for previous email, did not read the question properly. Sanju :) On Sun, Oct 9, 2011 at 7:12 PM, Sanjay Rajpal srn...@gmail.com wrote: After scanning the variable a, you will give a whitespace character(space,tab or newline), which will also get stored into stdin file. So next statement will scan this whitespace character. fflush(stdin) flushes(clears) the contents of stdin file, so this time scanf will not get whitespace character, instead it will get the character entered by user. or in second scanf statement, change it as scanf( %c,b), notice the space before %c. Correct me if m wrong :) Sanju :) On Sun, Oct 9, 2011 at 6:55 PM, rajul jain rajuljain...@gmail.com wrote: just take input a and b in one statement like this scanf(%d %d ,a ,b); On Sun, Oct 9, 2011 at 4:50 PM, Saravanan Selvamani saravananselvam...@gmail.com wrote: Hi, In the following programming when i gave character input rather than integer , the following scanf statement is not working . so i introduce the fflush(stdin) before the last scanf statement. But i get the same error as i before . #includestdio.h int main() { int a,b; scanf(%d,a); fflush(stdin); scanf(%d,b); printf(%d,b); //prints some garbage value. return 0; } so then what is the use of the fflush(stdin) and how to correct the above error? Thanks in advance. Regards P.S.Saravanan. -- why so serious? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] what is the use of fflush ?
these are some lines form fflush man pages For output streams, fflush() forces a write of all user-space buffered data for the given output or update stream via the stream's underlying write function. *For input streams, fflush() discards any buffered data that has been fetched from the underlying file, but has not been by the application.* * The standards do not specify the behavior for input streams.* Most other implementations behave the same as Linux. On Sun, Oct 9, 2011 at 7:17 PM, Sanjay Rajpal srn...@gmail.com wrote: Sorry for previous email, did not read the question properly. Sanju :) On Sun, Oct 9, 2011 at 7:12 PM, Sanjay Rajpal srn...@gmail.com wrote: After scanning the variable a, you will give a whitespace character(space,tab or newline), which will also get stored into stdin file. So next statement will scan this whitespace character. fflush(stdin) flushes(clears) the contents of stdin file, so this time scanf will not get whitespace character, instead it will get the character entered by user. or in second scanf statement, change it as scanf( %c,b), notice the space before %c. Correct me if m wrong :) Sanju :) On Sun, Oct 9, 2011 at 6:55 PM, rajul jain rajuljain...@gmail.comwrote: just take input a and b in one statement like this scanf(%d %d ,a ,b); On Sun, Oct 9, 2011 at 4:50 PM, Saravanan Selvamani saravananselvam...@gmail.com wrote: Hi, In the following programming when i gave character input rather than integer , the following scanf statement is not working . so i introduce the fflush(stdin) before the last scanf statement. But i get the same error as i before . #includestdio.h int main() { int a,b; scanf(%d,a); fflush(stdin); scanf(%d,b); printf(%d,b); //prints some garbage value. return 0; } so then what is the use of the fflush(stdin) and how to correct the above error? Thanks in advance. Regards P.S.Saravanan. -- why so serious? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] what is the use of fflush ?
don't fflush(stdin) it doesn't make any sense. fflush(stdout) and fflush(stderr) only. On Sun, Oct 9, 2011 at 8:20 AM, Saravanan Selvamani saravananselvam...@gmail.com wrote: Hi, In the following programming when i gave character input rather than integer , the following scanf statement is not working . so i introduce the fflush(stdin) before the last scanf statement. But i get the same error as i before . #includestdio.h int main() { int a,b; scanf(%d,a); fflush(stdin); scanf(%d,b); printf(%d,b); //prints some garbage value. return 0; } so then what is the use of the fflush(stdin) and how to correct the above error? Thanks in advance. Regards P.S.Saravanan. -- why so serious? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Hatta -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.