#include <stdio.h>
#include <string.h>
typedef struct
{
char item[50];
int date[15];
float price[5];
int amount[10];
float total[10];
}EXPENSES;
EXPENSES aExpenses;
int getOption();
void input();
void viewAll();
void del();
void edit();
int main (void)
{
int done = 0;
int option;
//while (!done)
option = getOption();
if (option == 5)
done = 1;
else
{
switch (option)
{
case 1: input;
break;
case 2: viewAll;
break;
case 4: del;
break;
case 5: edit;
break;
default : printf("Invalid selection");
}
}
return 0;
}
int getOption()
{
int option;
printf("\t====*MAIN MENU*====\n");
printf("\t1) Enter New data\n");
printf("\t2) View all data\n");
printf("\t3) Edit data\n");
printf("\t4) delete data\n");
printf("\t5) exit\n\n");
printf("enter your option: ");
scanf("d",&option);
return option;
}
void input(void)
{
char item;
int date;
float price;
int amount;
float total;
FILE* p;
p = fopen ("data.txt", "w");
fprintf(p,"%c\n", item);
fprintf(p,"%d\n", date);
fprintf(p,"%f\n", price);
fprintf(p,"%d\n", amount);
fprintf(p,"%f\n", total);
fclose(p);
return;
}
void viewAll()
{
char item;
int date;
float price;
int amount;
float total;
FILE* p;
p = fopen ("data.txt", "r");
fscanf(p,"%c %d %f %d %f", &item, &date, &price, &amount, &total);
fclose(p);
return;
}
void del()
{
char item;
int date;
float price;
int amount;
float total;
FILE* p;
p = fopen ("data.txt", "a");
fprintf(p,"%c\n", item);
fprintf(p,"%d\n", date);
fprintf(p,"%f\n", price);
fprintf(p,"%d\n", amount);
fprintf(p,"%f\n", total);
fclose(p);
return;
}
void edit()
{
char item;
int date;
float price;
int amount;
float total;
FILE* p;
p = fopen ("data.txt", "w");
fprintf(p,"%c\n", item);
fprintf(p,"%d\n", date);
fprintf(p,"%f\n", price);
fprintf(p,"%d\n", amount);
fprintf(p,"%f\n", total);
fclose(p);
return;
}
this program can run but when i execute it, it gives me the wrong output