struct Menu
{
float id;
char item[50];
struct Menu* subMenu[10];
} Menu[5] = {
{1, "SEARCH YOUR CONTACT", (struct Menu[]){{1.1, "ADD TO FAVOURITES"}, {1.2, "UPDATE"}, {1.3, "DELETE"}, {1.4, "ADD FIELD"}, {1.5, "BACK TO MAIN MENU"}}},
{2, "ADD CONTACT"},
{3, "DISPLAY FAVOURITES CONTACT", (struct Menu[]){{3.1, "ADD TO FAVOURITES"}, {3.2, "UPDATE"}, {3.3, "DELETE"}, {3.4, "ADD FIELD"}, {3.5, "BACK TO MAIN MENU"}}},
{4, "DISPLAY ALL CONTACT", (struct Menu[]){{4.1, "ADD TO FAVOURITES"}, {4.2, "UPDATE"}, {4.3, "DELETE"}, {4.4, "ADD FIELD"}, {4.5, "BACK TO MAIN MENU"}}},
{5, "EXIT APPLICATION"}
};
void menuItem()
{
for (int i = 0; i < 5; i++)
{
printf(" ... %.1f \\", Menu[0].subMenu[i]->id);
}
}
Output:
... 1.1 \Error: segmention fault
I tried printing method
printf("%.1f", Menu[0].subMenu[1]->id);
but it didn't work.
I want to print out all elements of the array struct.
subMenuentries.subMenuas an array of pointers, but you initialize it with an array of structure objects.floatas the id is probably not a good idea. What happens if you use an id that can't be represented exactly as afloat? And how would you use sub-sub-menus if you can't have e.g.1.1.1?x.yapart fromx.5cannot be represented exactly as they are periodic in binary...{ unsigned char level, char *item}and let the position in the array be id.