Code:
#include <stdio.h>
#include <math.h>
int Choice,Item_Code,Item_Qty,year,Halogen,i;
float Item_Price;
char Item_name [21],Item_date [21],Item_Value [10], choose;
int main ()
{
printf("\n*********************************************************");
printf("\n**********Electronic Component Inventory System**********");
printf("\n*********************************************************\n");
printf("\nMain Menu");
printf("\n---------");
printf("\n1.Show All Component List");
printf("\n2.Add Component");
printf("\n3.Remove Component");
printf("\n4.Search Item Inventory slot");
printf("\n5.Exit");
printf("\n\nPlease Choose your option:");
scanf("%d",&Choice);
switch (Choice)
{
case 1:
printf("You have selected Show All Component List\n");
FILE *f;
f = fopen("test.txt","r");
printf("\Code\tName\t\tValue\tPrice\tQty\tDate");
while (fscanf (f," %d",&Item_Code) !=EOF){
fscanf(f," %s", &Item_name);
fscanf(f," %s", &Item_Value);
fscanf(f," %f", &Item_Price);
fscanf(f," %d", &Item_Qty);
fscanf(f," %s", &Item_date);
printf("\n%d\t%s\t%s\t%.2f\t%d\t%s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);}
//{
//printf("%d",Item_Code);
//}
fclose(f);
break;
case 2:
print_item();
for(i=0;i<5;i++){
printf("\nDo you want to continue?Y/N = ");
scanf(" %c", &choose);
if(choose=='Y')
print_item();
else if(choose=='N')
break;}
case 3:
printf("You have selected Remove Component\n");
void search()
{
int sh;
design();
gotoxy(17,6);
printf("\xDB\xDB\xB2 Two options available to search \xB2\xDB\xDB");
gotoxy(15,9);
printf("[ 1 ] - Search by ID number .");
gotoxy(15,11);
printf("[ 2 ] - Search by Description .");
gotoxy(17,15);
printf("Enter your choice:: ");
sh=toupper(getch());
switch(sh)
{
case '1':
search_id();
break;
case '2':
search_name();
break;
default:
gotoxy(18,18);
printf("\a\xDB\xDB wrong entry try again");
getch();
}
getche();
}
break;
case 4:
printf("You have selected Search Item Inventory Slot\n");
break;
case 5:
printf("You have selected Exit\n");
break;
default:
printf("Invalid option selected\n");
}
return 0;
}
void print_item()
{
FILE *f;
printf("You have selected Add Component\n");
f = fopen("test.txt","a");
printf("Enter your Item Code :");
scanf ("\n %d",&Item_Code);
printf("Item Code = %d Recorded\n",Item_Code);
printf("Enter your Item Name :");
scanf ("\n %s",&Item_name);
printf("Item Name = %s Recorded\n",Item_name);
printf("Enter your Item Value :");
scanf ("\n %s",&Item_Value);
printf("Item Value = %s Recorded\n",Item_Value);
printf("Enter your Item Price :");
scanf ("\n %f",&Item_Price);
printf("Item Name = RM %.2f Recorded\n",Item_Price);
printf("Enter your Item Qty :");
scanf ("\n %d",&Item_Qty);
printf("Item Qty = %d Recorded\n",Item_Qty);
printf("Enter your Item Date :");
scanf ("\n %s",&Item_date);
printf("Item Date = %s Recorded\n",Item_date);
fprintf(f,"\n%d\t%s\t%s\t%.2f\t%d\t%s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);
//fprintf(f,"\n%d %s %s %.2f %d %s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);
fclose(f);
f = fopen("test.txt","r");
printf("\nItem Code Item Name Item Code Item Date");
while (fscanf (f," %d",&Item_Code) !=EOF){
fscanf(f," %s", &Item_name);
fscanf(f," %s", &Item_Value);
fscanf(f," %f", &Item_Price);
fscanf(f," %d", &Item_Qty);
fscanf(f," %s", &Item_date);
printf("\n%d\t%s\t%s\t%.2f\t%d\t%s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);}
//printf("\n%d %s %s %.2f %d %s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);}
fclose(f);
return 0;
}