Hi,
I'm having a strange error in my program. I my program has multiple function prototypes so I need a menu for the user to choice which function they need to use. When I use integers in my menu the switch statements work but when I use letters (char) instead I get errors and my program will not compile. I cannot figure out why it likes int better then char. Here is a few parts of the program with one prototype for example:
So when I try to compile the c compiler complains that " 'a' is undeclared (first use in this function)" as well as 'q', and any other charCode:/* Function Prototypes */ char MenuChoice(); void GetTotalDays(FILE*inFile); void clean (void); #define QUIT q #define GETTOTALDAYS a #define EVENTSGREATER5 b int main() { FILE *inFile; inFile=fopen(EventFile, "r"); if (inFile == NULL) { printf("Error in opening events.txt file\n"); } else { char choice; /*store choice for which function to test*/ do { choice = MenuChoice(); switch (choice) { case GETTOTALDAYS: printf("Running the program GetTotalDays...\n"); GetTotalDays(inFile); } break; default: if (choice!=QUIT) printf("\n That is not a valid test case, try again...\n"); break; } /* End Switch Statements*/ } while (choice !=QUIT); printf("Finishing the program.\n"); system("PAUSE"); return 0; } /*************************************/
but 'a' and 'q' etc. has been declared up at the beginning of the function and when I experiment and define "GETTOTALDAYS 1" it works.
Here is the rest of the code for the Menu:
Code:char MenuChoice() { char choice; printf(" Please Enter the letter corresponding to the function you wish to use:\n"); printf("%c: Quit the program.\n", QUIT); printf("%c: Use GetTotalDays(FILE *inFile)\n", GETTOTALDAYS); printf("%c: Use EventsGreater5(FILE *inFile)\n", EVENTSGREATER5); scanf("%c",&choice); clean(); printf("\n\n"); return choice; }
The same error saying that 'q', 'a', etc. is undeclared in the function prototype GetChoice
I would apprectiate any input at all please,
Thanks a ton,
melodia



LinkBack URL
About LinkBacks



