My program is crashing.
Basically, the data is not passing through the array for the menu choice and I am wondering if anyone could check it over and see where the problem is.
#include <stdio.h>
#include <stdlib.h>
void print_main_menu(char menu_items[5][10], int number_of_items) {
int i;
for (i = 0; i < number_of_items; i++) {
printf("%s\n", menu_items[0][i]);
}
}
int main () {
char menu [5][10];
menu [0][0] = "1 - Membership List";
menu [0][1] = "2 - Waiting List";
menu [0][2] = "3 - Committee List";
menu [0][3] = "4 - Temporary List";
menu [0][4] = "5 - Exit";
/* 1 - Membership List */
menu[1][0] = "1 - Whatever";
menu[1][1] = "2 - Whatever";
print_menu(menu, 5);
getch();
}
First off: you declared your function as
print_main_menubut you are calling it asprint_mainbut this should resolve into a compilation error.Secondly: you are using the two dimensional array incorrectly, apparantly you are using it as a two dimensional array of C strings, but you declared it as an array of characters.
This would be the right declaration:
Lastly: a lot of the array indices are not initialized, which means that they can point anywhere which will most likely produce a segmentation fault and crash your application.
EDIT: I’m also unsure if it is possible to pass an array to a function like you are doing it. It is most likely not a good idea to do so.