0% found this document useful (0 votes)
55 views5 pages

Void Gethomepage Struct Product: #Include #Include #Include

This C program defines functions for a basic inventory management system including login authentication, adding new products, making sales, and changing inventory quantities. The functions work together to provide an interactive menu-driven interface that allows users to view reports, enter/edit product data stored in a text file, and simulate sales by modifying the quantities in the file. Key functions include login() to authenticate users, enterNewProduct() to add new items, makeSale() to reduce quantities, and changeInventory() to modify existing product data.

Uploaded by

sohagiut
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views5 pages

Void Gethomepage Struct Product: #Include #Include #Include

This C program defines functions for a basic inventory management system including login authentication, adding new products, making sales, and changing inventory quantities. The functions work together to provide an interactive menu-driven interface that allows users to view reports, enter/edit product data stored in a text file, and simulate sales by modifying the quantities in the file. Key functions include login() to authenticate users, enterNewProduct() to add new items, makeSale() to reduce quantities, and changeInventory() to modify existing product data.

Uploaded by

sohagiut
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<stdio.h> #include<string.h> #include<stdlib.

h> void getHomepage(); struct Product { char name[200]; int quantity; float price; };

void menu(); void login() { char user_name[]="Munim"; char pass_word[]="122441"; char pass[100]; char user[100]; printf("Enter your name: "); scanf("%s",user); printf("Enter your password: \n"); scanf("%s",pass); if(!strcmp(user_name,user) && !strcmp(pass_word,pass))menu(); else printf("\nsign in error\n"); login();

} void enterNewProduct() { FILE *fp; char product_name[200]; int product_quantity; float product_price; struct Product new_product; int flag=0; printf("Enter new product's name:\n"); scanf(" %s",&new_product.name); fp=fopen("store.txt","r"); if(fp==NULL) printf("\nError:File does not exist.\n"); else { while(fscanf(fp,"%s %d %f",&product_name,&product_quantity,&product_price)!=EOF) { if(strcmp(product_name,new_product.name)==0) { printf("Product is alredy exists.\n"); flag=1; break;

} fclose(fp); if(flag==0) { printf("Enter new product's quantity:\n"); scanf("%d",&new_product.quantity); printf("Enter new product's price:\n"); scanf("%f",&new_product.price); fp==fopen("store.txt","a"); fprintf(fp,"\n%s %d %.2f",new_product.name,new_product.quantity,new_product.price); fclose(fp); }

} void makeSale() { FILE *fp,*fp2; char product_name[200]; int product_quantity; float product_price; struct Product new_product; char filename[]="store.txt"; int flag=0; printf("Enter a product's name:\n"); scanf(" %s",&new_product.name); fp=fopen(filename,"r"); fp2=fopen("copy.txt","w");

if(fp==NULL) printf("\nError:File does not exist.\n"); else { while(fscanf(fp,"%s %d %f",&product_name,&product_quantity,&product_price)!=EOF) { if(strcmp(product_name,new_product.name)==0) { printf("Enter new product's quantity:\n"); scanf("%d",&new_product.quantity); product_quantity=product_quantity-new_product.quantity; fprintf(fp2,"%s %d %.2f\n",product_name,product_quantity,product_price); flag=1; }

else { fprintf(fp2,"%s %d %.2f\n",product_name,product_quantity,product_price); } } } fclose(fp); fclose(fp2); remove(filename); rename("copy.txt",filename);

} void menu() { printf("\Menu:\n"); printf("============\n"); printf("\n1.Show Invetory report\n2.Enter new Product\n3.Make sale\n4.Change inventory\n\n"); } void getInventoryReport() { FILE *r; char product_name[200]; int product_quantity; float product_price; r=fopen("store.txt","r"); printf("%-20s %-10s %s\n","Product name","Quantity","Price"); if(r==NULL) printf("\nError:File does not exist.\n"); else { while(fscanf(r,"%s %d %f",&product_name,&product_quantity,&product_price) != EOF) { printf("%-20s %-10d %.2f\n",product_name,product_quantity,product_price); } } fclose(r); } void changeInventory() { FILE *fp,*fp2; char product_name[200]; int product_quantity; float product_price;

if(flag==0) { printf("Product isn't found.\n"); }

struct Product new_product; char filename[]="store.txt"; int flag=0; printf("Enter a product's name:\n"); scanf(" %s",&new_product.name); fp=fopen(filename,"r"); fp2=fopen("copy.txt","w");

if(fp==NULL) printf("\nError:File does not exist.\n"); else { while(fscanf(fp,"%s %d %f",&product_name,&product_quantity,&product_price)!=EOF) { if(strcmp(product_name,new_product.name)==0) { printf("Enter new product's quantity:\n"); scanf("%d",&new_product.quantity); product_quantity=new_product.quantity; fprintf(fp2,"%s %d %.2f\n",product_name,product_quantity,product_price); flag=1; } else { fprintf(fp2,"%s %d %.2f\n",product_name,product_quantity,product_price); } } } fclose(fp); fclose(fp2); remove(filename); rename("copy.txt",filename); if(flag==0) { printf("Product isn't found.\n"); }

} int main(void) { char option; login(); while(scanf("%c",&option)==1) { switch(option) { case '1':

getInventoryReport(); break; case '2': enterNewProduct(); break; case '3': makeSale(); break; case '4': changeInventory(); break; case 'h': menu(); break; case 'q': exit(1); } } return 0;

You might also like