Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<windows.h>
- #define MAX 100
- struct shop
- {
- char name [30];
- int price;
- int count;
- } shop_list[MAX];
- void init_list(void);
- void enter(void);
- int delet(void);
- void list(void);
- int menu_select(void);
- int find_free(void);
- int main(void)
- {
- char choice;
- init_list();
- for(;;)
- {
- system("cls");
- choice = menu_select();
- switch(choice)
- {
- case 1: enter();
- system("pause>0");
- break;
- case 2: delet();
- system("pause>0");
- break;
- case 3: list();
- system("pause>0");
- break;
- case 4: exit(0);
- }
- }
- return 0;
- }
- void init_list(void)
- {
- register int t;
- for (t=0; t<MAX; ++t) shop_list[t].name[0] = '\0';
- }
- int menu_select(void)
- {
- char s[80];
- int c;
- printf("1. Enter name\n");
- printf("2. Delete name\n");
- printf("3. Display the list\n");
- printf("4. Exit\n");
- do
- {
- printf("\nEnter the number of the desired item: ");
- gets(s);
- c = atoi(s);
- } while ((c<0 || c>4));
- return c;
- }
- void enter (void)
- {
- char name[80];
- int price;
- int count;
- printf("Enter name:");
- gets(name);
- for(int i=0;shop_list[i].name[0] && i < MAX;i++)
- {
- if(strcmp(shop_list[i].name,name) == 0)
- {
- printf("Product exists\n");
- printf("Enter just count:");
- scanf("%i",&count);
- shop_list[i].count = shop_list[i].count + count;
- return;
- }
- }
- printf("Enter price:");
- scanf("%i",&price);
- printf("Enter count:");
- scanf("%i",&count);
- register int i = 0;
- int slot;
- slot = find_free();
- if(slot==-1)
- {
- printf("\nList is full ");
- return;
- }
- else
- {
- strcpy(shop_list[slot].name,name);
- shop_list[slot].price = price;
- shop_list[slot].count = count;
- }
- }
- int find_free(void)
- {
- register int t;
- for (t=0; shop_list[t].name[0] !='\0' && t<MAX; ++t);
- if (t==MAX) return -1;
- return t;
- }
- int delet(void)
- {
- char s[80];
- printf("Enter name of product for del:");
- gets(s);
- register int i = 0;
- int flag = -1;
- for(i=0;shop_list[i].name[0] && i < MAX;i++)
- {
- if(strcmp(shop_list[i].name,s) == 0)
- {
- flag = 0;
- shop_list[i].name[0] = '\0';
- }
- }
- return flag;
- }
- void list(void)
- {
- register int t;
- for(t=0; t<MAX; ++t)
- {
- if(shop_list[t].name[0])
- {
- printf("%s ", shop_list[t].name);
- printf("%i ", shop_list[t].price);
- printf("%i\n", shop_list[t].count);
- }
- }
- printf("\n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement