All the values seem to be where they should be when I use or display them, but for some reason every time I get to a certain point (flagged in code), the program crashes.
The program is supposed to be adding a struct to an array. This struct contains another struct
along with an int denoting quantity. These are also being stored in an array.
Included are the main.c and functions surrounding the crash.
int main()
{
int choice;
int item_num;
int item_amount;
printf("*****MEAL PLANNER*****");
while(choice != 0)
{
prepopulate();
printf("\n\nTo view items, enter 1. \nTo view current menu, enter 2. \nTo add an item to the menu, enter 3. \nEnter 0 to exit.\n\n");
scanf("%d", &choice);
if(choice > 0 && choice < 5)
{
switch(choice)
{
case 1 : printf("\nView Items\n\n");
displayAllFoodStuff();
break;
case 2 :printf("\nView Current Menu\n\n");
display_meal();
break;
case 3 :printf("\nAdd Item to Menu\n\n");
printf("Enter item number.\n");
scanf("%d", &item_num);
printf("Enter item amount.\n");
scanf("%d", &item_amount);
if(item_num <= fs_count)
{
printf("Enter 1 to confirm.\n");
scanf("%d", choice);
fflush(stdin);
////////CRASHING HERE!!!////////
if(choice == 1)
{
choose_food_item(food_list[item_num], item_amount);
}
break;
}
else
{
printf("\nThat is not a valid entry.\n");
}
break;
default: choice = 0;
break;
}
}
}
return 0;
}
FUNCTIONS
//Define 'add_food_plan_item' function.
void add_food_plan_item(food_plan_item fs)
{
meal[item_count] = fs;
item_count++;
}
//Define 'choose_food_item' function.
void choose_food_item(food_stuff fs, int qty)
{
food_plan_item fpi;
fpi.fs = fs;
fpi.qty = qty;
add_food_plan_item(fpi);
}
Thanks in advance for any and all help.