Hello !
I've been trying to apply file handling in my program but I can't seem to make it work..
My program is for a shoe inventory .. Here's my code..
Thanks for the help !
I've been trying to apply file handling in my program but I can't seem to make it work..
My program is for a shoe inventory .. Here's my code..
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#define MAX 5
struct x
{
int no_of_pair;
} size[2];
struct style
{int nos;
int price;
struct x size[2];
} shoe[2];
struct stak
{ int no;
struct style shoe[2];
} stock[MAX];
int a=0;
void DISPLAY(struct stak j[])
{clrscr();
int b,menu;
for(b=0; b <= a; b++){
j[b].no = b+1;
printf(" shoe\tshoe size no. of price\n no. style\t \t pairs\n\n");
printf(" %d **************************************\n *** 1 *** 12 ** %d ** %d\n", j[b].no,j[b].shoe[0].size[0].no_of_pair,j[b].shoe[0].price);
printf(" *** *** 13 ** %d\n",j[b].shoe[0].size[1].no_of_pair);
printf(" *** *** 14 ** %d\n\n",j[b].shoe[0].size[2].no_of_pair);
printf(" *** 2 *** 12 ** %d ** %d\n",j[b].shoe[1].size[0].no_of_pair,j[b].shoe[1].price);
printf(" *** *** 13 ** %d\n",j[b].shoe[1].size[1].no_of_pair);
printf(" *** *** 14 ** %d\t\n\n",j[b].shoe[1].size[2].no_of_pair);
printf(" *** 3 *** 12 ** %d ** %d\n",j[b].shoe[2].size[0].no_of_pair,j[b].shoe[2].price);
printf(" *** *** 13 ** %d\n",j[b].shoe[2].size[1].no_of_pair);
printf(" *** *** 14 ** %d\n",j[b].shoe[2].size[2].no_of_pair);
}
printf("\n\nreturn to menu??(Press 0 if yes and 1 if not)");
scanf("%d",&menu);
if(menu == 1)
exit(0);
}
void ADD(struct stak k[])
{
a+=1;
printf("\nEnter the no. of pairs for each size in each style .\n");
printf("\nStyle 1: \n 12\":\t");
scanf("%d",&k[a].shoe[0].size[0].no_of_pair);
printf("\n13\":\t");
scanf("%d",&k[a].shoe[0].size[1].no_of_pair);
printf("\n14\":\t");
scanf("%d",&k[a].shoe[0].size[2].no_of_pair);
printf("Enter the price for Style 1:\t");
scanf("%d",&k[a].shoe[0].price);
printf("\n\nStyle 2: \n 12\":\t");
scanf("%d",&k[a].shoe[1].size[0].no_of_pair);
printf("\n13\":\t");
scanf("%d",&k[a].shoe[1].size[1].no_of_pair);
printf("\n14\":\t");
scanf("%d",&k[a].shoe[1].size[2].no_of_pair);
printf("Enter the price for Style 2:\t");
scanf("%d",&k[a].shoe[1].price);
printf("\n\nStyle 3: \n 12\":\t");
scanf("%d",&k[a].shoe[2].size[0].no_of_pair);
printf("\n13\":\t");
scanf("%d",&k[a].shoe[2].size[1].no_of_pair);
printf("\n14\":\t");
scanf("%d",&k[a].shoe[2].size[2].no_of_pair);
printf("Enter the price for Style 3:\t");
scanf("%d",&k[a].shoe[2].price);
}
void EDIT(struct stak l[])
{
int ans;
int styles;
int change, choice;
int prize;
printf("What stock number do you want to edit?\n");
printf("Here are your choices : \n1. 1\t 2. 2\t 3. 3 \n");
scanf("%d",&ans);
if(ans==0)
printf("INvalid Stock no. !");
else
{ ans-=1;
if(ans>a)
printf("NO STOCK NUMBER EXISTS!");
else
{printf("What styles would it be ?\n");
printf("Here are your choices :\n1. 1\t 2. 2\t 3. 3 \n");
printf("Enter your choice\n");
scanf("%d",&styles);
if(styles==0)
printf("Invalid Style !");
else { styles-=1;
if(styles>2)
printf("NO STYLE EXISTS !");
printf("What do you want to change?\n Here are the choices: \t1. Price \t 2. No. of Pairs");
scanf("%d",&change);
if(change==1)
{ printf("Enter the new price:\t");
scanf("%d",&l[ans].shoe[styles].price);
}
else{
if(change==2)
{ printf("What would be the shoe size ? 1. 12\" ?\t 2. 13\" ?\t 3. 14\"?\n");
scanf("%d",&choice);
printf("Enter the new no. of pairs:\t ");
scanf("%d",&l[ans].shoe[styles].size[choice-1].no_of_pair);
}
}
}
}
}
}
main()
{
struct stak stock[MAX];
int sagot;
stock[0].shoe[0].price=1500;
stock[0].shoe[1].price=2500;
stock[0].shoe[2].price=3700;
stock[0].shoe[0].size[0].no_of_pair=5;
stock[0].shoe[0].size[1].no_of_pair=7;
stock[0].shoe[0].size[2].no_of_pair=10;
stock[0].shoe[1].size[0].no_of_pair=6;
stock[0].shoe[1].size[1].no_of_pair=8;
stock[0].shoe[1].size[2].no_of_pair=11;
stock[0].shoe[2].size[0].no_of_pair=7;
stock[0].shoe[2].size[1].no_of_pair=9;
stock[0].shoe[2].size[2].no_of_pair=12;
do{
clrscr();
gotoxy(27,2);
printf("SHOE INVENTORY\n\n");
printf("What do you want to do ?\n1.DISPLAY\n2.ADD\n3.EDIT\n4.EXIT");
scanf("%d",&sagot);
switch(sagot)
{
case 1: DISPLAY(stock);break;
case 2: ADD(stock); break;
case 3: EDIT(stock); break;
case 4: exit(0); break;
default : printf("Error!"); }
}
while(sagot!=4);
getch();
}
Comment