> fflush (stdin);
http://faq.cprogramming.com/cgi-bin/...&id=1043284351
> I'm supposed to read in the time given by the user.
Basically, you read all input as a string, then parse that string to see what the user typed.
Code:
#include <stdio.h>
int main ( ) {
char buff[100];
if ( fgets( buff, sizeof buff, stdin ) != NULL ) {
int now;
char ampm[3];
if ( sscanf( buff, "%d%2s", &now, ampm ) == 2 ) {
printf( "12 hr time = %d %s\n", now, ampm );
} else if ( sscanf( buff, "%d", &now ) == 1 ) {
printf( "24 hr time = %04d\n", now );
} else {
printf( "Huh?\n" );
}
}
return 0;
}