Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- typedef struct supermarket
- {
- char pr[50];
- int q;
- int bp;
- int sp;
- int qs;
- }supermarket;
- int main()
- {
- supermarket s;
- char password[50]={"apple"};
- char user[50]={"admin"};
- char p[6];
- char u[6];
- char pname[20],ename[20];
- printf("--------LOG-IN Form--------\n");
- printf("\nEnter Username and Password.\nUsername: ");
- scanf("%s",&u);
- printf("Password: ");
- scanf("%s",&p);
- int i,c=0,d=0,n,ch;
- for(i=0;p[i]!='\0';i++)
- {
- if(u[i]==user[i])
- {
- c++;
- }
- if(p[i]==password[i])
- {
- d++;
- }
- }
- if(c==5 && d==5)
- {
- for(i=1;;i++)
- {
- 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");
- scanf("%d",&ch);
- if(ch<1 || ch>=6)
- break;
- if(ch==5)
- {
- FILE *f;
- f=fopen("Supermarket.txt","w");
- fprintf(f,"\n");
- fclose(f);
- printf("\nAll the records has been deleted.\n");
- }
- if(ch==1)
- {
- FILE *f;
- f=fopen("Supermarket.txt","a+");
- printf("\nEnter the following information:\nProduct\nQuantity\nBuying price\nSelling price\nTotal quantity sold\n\n");
- printf("Product: ");
- scanf("%s",&s.pr);
- printf("Quantity: ");
- scanf("%d",&s.q);
- printf("Buying price: ");
- scanf("%d",&s.bp);
- printf("Selling price: ");
- scanf("%d",&s.sp);
- printf("Quantity sold: ");
- scanf("%d",&s.qs);
- printf("\n");
- 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);
- fclose(f);
- }
- if(ch==2)
- {
- printf("\nOpen the FILE to check the record.\n");
- }
- if(ch==3)
- {
- FILE *f;
- f=fopen("Supermarket.txt","a+");
- printf("Enter product name: ");
- scanf("%s",&pname);
- if (strcmp(pname,s.pr)==0)
- {
- fprintf(f,"\n\nSearched Record:-\n");
- 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);
- printf("\nOpen the FILE to check the searched product info.\n");
- }
- else
- {
- printf("\nThere's no product in the name of \"%s\"\n",pname);
- }
- fclose(f);
- }
- if(ch==4)
- {
- FILE *f;
- f=fopen("Supermarket.txt","a+");
- printf("Enter the product that you want to edit: ");
- scanf("%s",&ename);
- if(strcmp(ename,s.pr)==0)
- {
- printf("\nEnter new product name, Quantity, Buying price, Selling price, Quantity sold:\n");
- printf("\nEnter the following information:\nProduct\nQuantity\nBuying price\nSelling price\nTotal quantity sold\n\n");
- printf("Product: ");
- scanf("%s",&s.pr);
- printf("Quantity: ");
- scanf("%d",&s.q);
- printf("Buying price: ");
- scanf("%d",&s.bp);
- printf("Selling price: ");
- scanf("%d",&s.sp);
- printf("Quantity sold: ");
- scanf("%d",&s.qs);
- printf("\n");
- 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);
- }
- else
- {
- printf("\nThere's no product in the name of \"%s\"\n",ename);
- }
- fclose(f);
- }
- }
- }
- else
- printf("\nWrong Username and Password combination.\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement