Hey Folks,
This recursive menu function is supposed to only list the options once, before menu_shown is incremented. However, the options are still being listed each time I default. Does anyone see why this is happening? Also, should I use fpurge instead of fflush? Thanks in advance for any insights. menu_shown is initialized globally as
Code:
menu () /* gets menu choice and calls */
{ /* the appropriate function */
char choice=0;
int exit_code;
if (menu_shown == 0);
{
printf ("\nYou have the following options:\n");
printf ("1) Add new contact\n");
printf ("2) Search\n");
printf ("3) Quit\n");
menu_shown++;
}
printf ("\nPlease choose an option.\n>");
choice = getchar();
fflush(stdin);
switch (choice)
{
case '1' :
break;
case '2' :
search ();
case '3' :
exit (exit_code);
default :
printf ("You've only got three choices, how hard can it be?\a\n");
menu ();
}
}