fflush(stdin) in ubuntu (linux)
At programming c / c you often encounter drift phenomenon command (fails to enter data). To remedy this situation, you use the ffulsh(stdin) to clear the buffer. But on Linux does not have this function, please replace it with the command
__fpurge(stdin);
Code examples:
#include <stdio.h> // io #include <stdio_ext.h> // __fpurge(stdin); int main() { int x; char s[100]; // scan a number printf("enter number x = "); scanf("%d", &x); // clear stdin __fpurge(stdin); // scan a string printf("enter a string: "); gets(s); printf("number is %d \nstring is %s\n", x,s); return 0; }
enter number x = 7826 enter a string: nguyen van quan number is 7826 string is nguyen van quan
Read more gets() and fget() in C/C
you ask yourself on using library functions do because I build on the library of ubuntu it does not run.
It is located in the library stdio_ext.h nhé you
thanks bro!
Sir >< he can explain why PES sir
Why something you?