To fflush, or Not to fflush...
I am going through the C for Dummies tutorials and have run into a problem using fflush.
Code:
#include <stdio.h>
int main()
{
char c,d;
printf("Enter a key, blah blah blah:\n");
c=getchar();
fflush(stdin);
printf("Enter a different key, blah blah blah:\n");
d=getchar();
if(c=='G' || c=='g' && d=='0')
{
printf("**** AUTO DESTRUCT ACTIVATED ****\n");
printf("**** GOODBYE ****\n");
}
else
{
printf("Nice job moron.\n");
}
return (0);
}
A) When I use fflush, it compiles just fine, no errors.
But when the program runs, and I type e I get the following result:
Enter a key, blah blah blah:
At the prompt I can type a letter...I choose 'e', then hit return and it spits out the next three lines, end program.
e
Enter a different key, blah blah blah:
Nice job moron.
B) When I use fpurge the compiler returns an error that reads:
ld: Undefined symbols:
___gxx_personality_v0
Sorry for the lengthy description, can anyone help me out?
Bryan a.k.a. New Guy
So...no fflushing, got it!
Thank you for your response.
The puzzler here is that fflush doesn't register an error when compiling, yet it doesn't work.
fpurge ALSO recommended by Mr. Gookin (he does mention that fflush isn't the only way to do it) DOES return an error during compiling!?
I have looked through the forum, and there seem to be really complex ways to clear the input buffer...
I would like to know how to figure out what I AM supposed to use with the gcc compiler?
My shell recognizes man fflush and fpurge as the same thing, they effect differently and neither of them works!?
Definitely don't like being the new guy with the stoopid questions!
Apologies,