I have a menu program but want to change it from using numbers to using Characters. I think I understand most of what I need to change. But and confused on the error checking and exactly what I would be passing. OK at this point am I even being coherent in my question, and am I on the right track or should I look at doing this another way?
Here are some samples of the code to see if that helps clear it up.
Menu Code:
As I said, I think I am on track here (but that could be wrong, I am just confused on the error hadling, and perhaps what I really should be passing. My original error handling was done for a menu program that used numbers and not letters.Code:char getMenu (void) { char choice; do { printf("\t* Menu *\n"); printf("\t* *\n"); printf("\t* A. Function A *\n"); printf("\t* E. Function E *\n"); printf("\t* W. Last Function *\n"); printf("\t* E. Get me out of here *\n"); printf("\t* *\n"); printf("Please select a menu option and press <retrun>: "); scanf("%c", &choice); // error handling is done here if (choice <1 || choice >4) { system ("cls"); printf("\aSorry, but this is not a valid option. Please select again.\n\n"); while ( getchar() != '\n' ); } } while (choice <1 || choice >4); return choice; }
Also if I using a switch in the main to call the functions from what is passed by the menu, how do I ID the cases to get accesed? Or should I not be using a switch. As far as I know, a switch can only be numbers...Is this right or wrong? And do I convert the text to numbers for the switch or as I have said, am I totally off track and should be looking for another way to make this work?
As always any advice and help is greatly appreciated.
Thanks
DD