Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void add()
- {
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- int sign;
- char ch;
- f = fopen(name, "r+b");
- fread(&list, sizeof(struct product), n, f);
- int j = n;
- do
- {
- SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | 4));
- printf("Input type of product: 1- drink 2-chocolate: ");
- SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | 0));
- scanf("%d", &sign);
- if (sign == 1) list[j].tag = DRINK;
- else list[j].tag = CHOCOLATE;
- switch (list[j].tag)
- {
- case DRINK:
- { printf("name of drink: ");
- scanf("%s", list[j].name);
- printf("Enter calor of drink: ");
- scanf("%d", &list[j].calor);
- printf("Enter value of drink: ");
- scanf("%d", &list[j].value);
- printf("Enter strength of drink: ");
- scanf("%d", &list[j].drink.strength); break;
- }
- case CHOCOLATE:
- {
- printf("Enter name of chocolate:");
- scanf("%s", list[j].name);
- printf("Enter calor of chocolate: ");
- scanf("%d", &list[j].calor);
- printf("Enter value of chocolate: ");
- scanf("%d", &list[j].value);
- printf("Enter weigth of chocolate: ");
- scanf("%d", &list[j].chocolate.weigth);
- printf("Enter filling of chocolate: ");
- scanf("%s", list[j].chocolate.filling); break;
- }
- } //end of switch
- SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | 2));
- printf("Continue? [y/n] ");
- SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | 0));
- getchar();
- ch = getchar();
- j++;
- } while ((ch != 'n') && (ch != 'N'));
- fclose(f);
- n = j;
- f = fopen(name, "r+b");
- for (j = 0; j < n; j++)
- {
- fwrite(&list[j],sizeof(struct product),1,f);
- }
- fclose(f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement