> fflush(stdin);
This isn't defined - if it works at all, it's a compiler specific thing
See the FAQ
Best bet is
Code:
char buff[BUFSIZ];
if ( fgets( buff, sizeof buff, stdin ) != NULL ) {
error = sscanf( buff, "%d", &menu_choice );
} else {
/* exit while() loop - its EOF - no more input is possible */
break;
}
> while ( menu_choice < 1 || menu_choice > 5 && error == 0);
Close!
But you should choose a better order.
If error is 0, then menu_choice is undefined (you didn't read anything into it)
while ( error == 0 || menu_choice < 1 || menu_choice > 5 );
Only tests menu_choice if error is not zero (that is, error is 1 and menu_choice has a valid value).