Here's one possible way to do it.
Code:
#include <stdio.h>
#define NO_FLAG 1
#define BAD_FLAG 2
static char *err_msg[] = {
"No errors detected",
"No flag found",
"Invalid flag",
};
int main ( void )
{
int error;
char val[4] = {0};
/*
** Lots of code...
*/
fgets ( val, sizeof val, stdin );
/*
** No errors if error maintains a value of 0
*/
error = 0;
if ( val[0] == '-' ) {
if ( val[1] != 'f' )
error = BAD_FLAG;
}
else
error = NO_FLAG;
/* Report error status */
fprintf ( stderr, "error: %s\n", err_msg[error] );
return 0;
}
-Prelude