First and foremost, turn on warning options in your compiler. Your compiler should have warned you there was a type mismatch.
MenuOptions is an array of seven arrays of 200 char. When displayMenu is called, and MenuOptions is passed as a parameter, MenuOptions is automatically converted from an array to a pointer to the first of the seven arrays of 200 char.
In displayMenu, the options parameter is declared with char *options[]. This means that options is an array of pointers to char. In function parameters, [] is special; it suggests that an array will be passed for this parameter, but the array is actually passed by the address of its first argument. Thus, this declaration says that options is a pointer to the first of some number of pointers to char.
So, you are passing a pointer to the first of seven arrays of 200 char, but the function expects to receive a pointer to the first of some number of pointers to char.
One way to fix this is to change the declaration of options to char (*options)[200]. This says that options is a pointer to (the first of) arrays of 200 char.
A better way to fix it may be to change MenuOptions:
static const char *MenuOptions[] =
{
"Create New / Modify Existing Customer",
"Create New / Modify Existing Product",
"List All customers",
"List All Products",
"Batch Update of New Stock",
"Create Customer Order",
"View Last Order for Customer",
};
(You do not need “7” in the brackets because the compiler will count the strings for you.)
Then you do not need to change the declaration of options, except that I have added const:
char displayMenu(char *name, const char *options[], int menuLength,
enBoolean QuitEnabled) {…
Now:
MenuOptions is an array of seven pointers to strings (arrays of char). It is passed as a pointer to pointers to strings, and options is a pointer to pointers to strings, so the types match.
MenuOptions does not take more space than required. Before, it was defined with 200 characters for each string. Now, each string takes only as much space as it needs (plus a null character at the end and a pointer to the string in the MenuOptions array).
const is added to avoid accidentally changing the strings.
MenuOptions is declared static, so that it is initialized at compile time, and you do not need to copy strings into it at run time.
Finally, you can replace the “7” in the call to displayMenu with sizeof MenuOptions / sizeof *MenuOptions. This divides the size of the array by the size of an element of the array, giving the number of elements in the array. This is preferred over hard-coding a constant because it eliminates the possibility that somebody might change the size of the array without changing the hard-coded constant.
etcas your code doesn't really help anything. Why not just post the actual code instead?ectseems completely appropriate, if not preferable. The error he is reporting seems to be happening before those lines would ever be reached. Posting to much code just makes it harder to read.char* MenuOptions[] = {"Create New / Modify Existing Customer", ... , "View Last Order for Customer"};but you need to post the return section of displayMenu ... it should be an integer value