1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
void items();
struct record{
char code[2], name[10];
int q;
}product;
char ans, choice, erase, D[2], tc;
char newcode[2];
int X;
int main ()
{
FILE *fp, *fa;
fp = fopen("Products.txt", "w");
do
{
items();
fprintf(fp,"\n\n%.2s\n%s\n%d", product.code, product.name, product.q);
} while (toupper(ans)=='Y');
fclose(fp);
//do{
printf("\n\nA-ADD\tD-DELETE\tE-EDIT\tT-TRANSACT\tX-EXIT");
printf("\n\nWhat do you want to do? ");
scanf(" %c", &choice);
if (toupper(choice)=='A')
{
fp = fopen("Products.txt", "a");
printf("\n\n");
items();
fprintf(fp,"\n\n%.2s \n%s \n%d", product.code, product.name, product.q);
fclose(fp);
}
/* else if (toupper(choice)=='D')
{ int success =0;
printf("Product Code: ");
scanf("\n");
gets(newcode);
fp = fopen("Products.txt","r");
fa = fopen("temproducts.txt", "w");
while (fscanf(fp, "%.2s \n%s \n%d", &product.code, &product.name, &product.q)!=EOF)
{
if(strcmp(newcode,product.code)==0)//if code is same
{
printf("%.2s \n %s \n %d", product.code, product.name, product.q);
printf("Delete the record? [Y / N] ");
scanf("%c", &erase);
if (toupper(erase)=='Y')
{
printf("Deleted!");
success = 1;
}
else //not yes
{
printf("\n\nPress Enter to continue...");
fprintf(fp,"\n\n%.2s\n%s\n%d", product.code, product.name, product.q);
success=1;
}
}
else
{
fprintf(fa,"\n\n%.2s\n%s\n%d", product.code, product.name, product.q);
}
}
}
fclose (fp);
getch();
}
void items()
{
printf("Enter Product Code: ");
scanf("\n");
gets(product.code);
printf("Enter Product Name: ");
scanf("\n");
gets(product.name);
printf("Quantity: ");
scanf("%d", &product.q);
printf("Enter More? [Y/N] ");
scanf(" %c", &ans);
printf("\n\n");
} */
|