void modifyMenu()
{
int i = 0, j, found = 0;
int select=0;
char inputID[20];
char input;
struct Menu fo[100];
FILE *fp;
fp = fopen("foodMenu.txt", "r");
if (fp == NULL)
{
printf("Unable to open the file\n");
exit(-1);
}
else
{
while (fscanf(fp, "%[^|]|%[^|]|%[^|]|%[^|]|%f\n", &fo[i].foodID, &fo[i].category, &fo[i].foodName, &fo[i].foodDescription, &fo[i].foodPrices) != EOF)
i++;
}
fclose(fp);
system("cls");
printf("Modify Menu\n");
printf("====================================\n");
printf("Please enter the food in menu you want to modify :\n");
rewind(stdin);
scanf("%s", &inputID);
for (j = 0; j < i; j++)
if (strcmp(fo[j].foodID, strupr(inputID))==0)
{
system("cls");
printf("Modify\n");
printf("FOOD ID:%s\n", inputID);
rewind(stdin);
printf("Enter the food category:\n");
scanf("%s", &fo[j].category);
rewind(stdin);
printf("Enter the food name:\n");
scanf("%s", &fo[j].foodName);
rewind(stdin);
printf("Enter the food description:\n");
scanf("%s", &fo[j].foodDescription);
rewind(stdin);
printf("Enter the food prices:\n");
scanf("%f", &fo[j].foodPrices);
rewind(stdin);
found++;
printf("Modify done\n");
}
fp = fopen("foodMenu.txt", "w");
for (j = 0; j < i; j++) {
fprintf(fp, "%[^|]|%[^|]|%[^|]|%[^|]|%.2f\n", &fo[j].foodID, &fo[j].category, &fo[j].foodName, &fo[j].foodDescription, &fo[j].foodPrices);
}
fclose(fp);
if (found == 0)
printf("This ID is not avaiable\n");
system("pause");
do {
system("cls");
printf("Do you want to proceed again ?(Y/N)");
rewind(stdin);
scanf("%c", &input);
if (input == 'N' || input == 'n')
{
do {
home();
} while (select != 1 || select != 2 || select != 3 || select != 4 || select != 5);
}
else if (input == 'Y' || input == 'y')
break;
else
printf("Error input!!\nPlease enter again!!!!\n");
} while (input != 'Y' || input != 'y' || input != 'N' || input != 'n');
}
You’re missing some crucial information here, which is why it’s hard to get help because things won’t compile for us anyway.
We need info like the libraries you included.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct Menu fo[100]; // NOT IN CODE.
if (strcmp(fo[j].foodID, strupr(inputID)==0)) // PROBLEM WITH strupr() that needs to be looked at
home(); // NOT IN CODE.