Advertisement
TheShaanx

Supermarket project

Dec 24th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.75 KB | None | 0 0
  1. #include<stdio.h>
  2. typedef struct supermarket
  3. {
  4.     char pr[50];
  5.     int q;
  6.     int bp;
  7.     int sp;
  8.     int qs;
  9. }supermarket;
  10. int main()
  11. {
  12.     supermarket s;
  13.     char password[50]={"apple"};
  14.     char user[50]={"admin"};
  15.     char p[6];
  16.     char u[6];
  17.     char pname[20],ename[20];
  18.     printf("--------LOG-IN Form--------\n");
  19.     printf("\nEnter Username and Password.\nUsername: ");
  20.     scanf("%s",&u);
  21.     printf("Password: ");
  22.     scanf("%s",&p);
  23.     int i,c=0,d=0,n,ch;
  24.     for(i=0;p[i]!='\0';i++)
  25.     {
  26.         if(u[i]==user[i])
  27.         {
  28.             c++;
  29.         }
  30.  
  31.         if(p[i]==password[i])
  32.         {
  33.             d++;
  34.         }
  35.     }
  36.     if(c==5 && d==5)
  37.         {
  38.             for(i=1;;i++)
  39.             {
  40.                 printf("\nSelect an option:\n1. Add record. (press 1)\n2. Show record. (Press 2)\n3. Search record. (Press 3)\n4. Edit record. (Press 4)\n5. Delete record. (Press 5)\n6. Exit. (press 6)\n");
  41.                 scanf("%d",&ch);
  42.  
  43.                 if(ch<1 || ch>=6)
  44.                     break;
  45.  
  46.                 if(ch==5)
  47.                 {
  48.                     FILE *f;
  49.                     f=fopen("Supermarket.txt","w");
  50.                     fprintf(f,"\n");
  51.                     fclose(f);
  52.                     printf("\nAll the records has been deleted.\n");
  53.                 }
  54.  
  55.                 if(ch==1)
  56.                 {
  57.                     FILE *f;
  58.                     f=fopen("Supermarket.txt","a+");
  59.                     printf("\nEnter the following information:\nProduct\nQuantity\nBuying price\nSelling price\nTotal quantity sold\n\n");
  60.                     printf("Product: ");
  61.                     scanf("%s",&s.pr);
  62.                     printf("Quantity: ");
  63.                     scanf("%d",&s.q);
  64.                     printf("Buying price: ");
  65.                     scanf("%d",&s.bp);
  66.                     printf("Selling price: ");
  67.                     scanf("%d",&s.sp);
  68.                     printf("Quantity sold: ");
  69.                     scanf("%d",&s.qs);
  70.                     printf("\n");
  71.                     fprintf(f,"\nProduct: %s\nQuantity: %d\nBuying price: %d\nSelling price: %d\nQuantity sold: %d\n\n",s.pr,s.q,s.bp,s.sp,s.qs);
  72.                     fclose(f);
  73.                 }
  74.  
  75.                 if(ch==2)
  76.                 {
  77.                     printf("\nOpen the FILE to check the record.\n");
  78.                 }
  79.  
  80.                 if(ch==3)
  81.                 {
  82.                     FILE *f;
  83.                     f=fopen("Supermarket.txt","a+");
  84.                     printf("Enter product name: ");
  85.                     scanf("%s",&pname);
  86.                     if (strcmp(pname,s.pr)==0)
  87.                     {
  88.                         fprintf(f,"\n\nSearched Record:-\n");
  89.                         fprintf(f,"\nProduct: %s\nQuantity: %d\nBuying price: %d\nSelling price: %d\nQuantity sold: %d\n\n",s.pr,s.q,s.bp,s.sp,s.qs);
  90.                         printf("\nOpen the FILE to check the searched product info.\n");
  91.                     }
  92.                     else
  93.                     {
  94.                         printf("\nThere's no product in the name of \"%s\"\n",pname);
  95.                     }
  96.                     fclose(f);
  97.                 }
  98.  
  99.                 if(ch==4)
  100.                 {
  101.                     FILE *f;
  102.                     f=fopen("Supermarket.txt","a+");
  103.                     printf("Enter the product that you want to edit: ");
  104.                     scanf("%s",&ename);
  105.                     if(strcmp(ename,s.pr)==0)
  106.                     {
  107.                         printf("\nEnter new product name, Quantity, Buying price, Selling price, Quantity sold:\n");
  108.                         printf("\nEnter the following information:\nProduct\nQuantity\nBuying price\nSelling price\nTotal quantity sold\n\n");
  109.                         printf("Product: ");
  110.                         scanf("%s",&s.pr);
  111.                         printf("Quantity: ");
  112.                         scanf("%d",&s.q);
  113.                         printf("Buying price: ");
  114.                         scanf("%d",&s.bp);
  115.                         printf("Selling price: ");
  116.                         scanf("%d",&s.sp);
  117.                         printf("Quantity sold: ");
  118.                         scanf("%d",&s.qs);
  119.                         printf("\n");
  120.                         fprintf(f,"\nEdited Info:-\n\nProduct: %s\nQuantity: %d\nBuying price: %d\nSelling price: %d\nQuantity sold: %d\n\n",s.pr,s.q,s.bp,s.sp,s.qs);
  121.                     }
  122.                     else
  123.                     {
  124.                         printf("\nThere's no product in the name of \"%s\"\n",ename);
  125.                     }
  126.                     fclose(f);
  127.                 }
  128.             }
  129.         }
  130.     else
  131.         printf("\nWrong Username and Password combination.\n");
  132.  
  133. return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement