I have been getting good results with a code like this:
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
char buff[24];
/* reads max 1 character from stdin */
fgets( buff, 2, stdin );
/* shows what has been read */
printf( "\nYou wrote: %s\n\n", buff );
/* clears any "extra" character */
fflush( stdin );
/* reads max 19 characters from stdin */
fgets( buff, 20, stdin );
/* shows what has been read */
printf( "\nYou wrote: %s\n\n", buff );
/* clears any "extra" character */
fflush( stdin );
return 0;
}
If you need to get ints or floats as input instead of strings, just feed atoi() or atof() with the buff string.