i have two problems first on the compile time warning : warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] MenuFunction fp;
and second i am always end to "Error: buffer overflow. Please try again, entering less data" what i am doing wrong i have no idea , please help me to figure this out.
typedef void (*MenuFunction)(System*);
int main(int argc, char ** argv)
{
...
/* While loop for my menu */
while(1)
{
printf("Main Menu\n");
printf("%s\n", menu[0].text);
printf("%s\n", menu[1].text);
printf("%s\n", menu[2].text);
printf("Select your option (1-3): ");
MenuFunction fp;
fp = getMenuChoice(menu);
if(fp == NULL){
fprintf(stderr, "invalid choice\n");
}
else{
(*fp)(&system);
}
}
}
/* Function that points to the menu function */
MenuFunction getMenuChoice(MenuItem * menu)
{
MenuFunction function = NULL;
char select[50];
fgets(select, 50, stdin);
if(select[strlen(select)-1] == '\n')
{
switch(select[0])
{
case '1':
function = menu[0].function;
break;
case '2':
function = menu[1].function;
break;
case '3':
function = menu[2].function;
exit(0);
break;
default:
printf("Invalid option\n");
}
}
else
{
readRestOfLine();
printf("Error: buffer overflow. Please try again, entering less data");
}
return function;
}