Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<malloc.h>
- #define MAX_LENGTH 80
- #define LOOPS 1
- struct delivery
- {
- int num;
- char name[20];
- char code[8];
- char info[80];
- int day;
- int month;
- int year;
- int amount;
- };
- typedef struct delivery BODY;
- struct List{
- BODY body;
- struct List*pNext;
- };
- typedef struct List LIST;
- int enterBody(BODY*ps);
- void printBody(BODY s);
- void printList(LIST*pFirst, int pm, int py);
- LIST*insertBegin(LIST*pFirst, BODY newBody);
- int main()
- {
- FILE*pOut = NULL, *pIn = NULL;
- char Fname[] = "List_bin.dat";
- BODY newbody;
- LIST*pFirst = NULL, *p;
- int res, i, mode, pm, py;
- char sfn[20], gr[20];
- int newgr, fn;
- BODY delivery;
- char*menu[] = { "MENU:",
- "1 - Enter info for new delivery ",
- "2 - Print info for deliveries for an entered month ",
- };
- do
- {
- system("cls");
- for (i = 0; i < 3; i++)
- printf("n%sn", menu[i]);
- do
- {
- fflush(stdin);
- printf("nChoose operation (1-2): ");
- res = scanf("%d", &mode);
- } while (res != 1);
- switch (mode)
- {
- case 1:
- for (i = 0; i < LOOPS; i++)
- {
- res = enterBody(&delivery);
- if (res != 1)
- {
- printf("Error in initialization %dn", res);
- break;
- }
- p = insertBegin(pFirst, delivery);
- if (p == NULL)
- {
- printf("Not enough memory! ");
- break;
- }
- pFirst = p;
- }
- system("pause");
- break;
- case 2:
- printf("nEnter month: ");
- scanf("%19s", pm);
- printf("nEnter year: ");
- scanf("%19s", py);
- if (pFirst != NULL)
- {
- printList(pFirst, pm, py);
- }
- else printf("nEmpty list!n");
- system("pause");
- break;
- default:
- printf("nIncorrect operation!n");
- system("pause");
- }
- } while (mode != 11);
- system("pause");
- return 0;
- }
- int enterBody(BODY*ps)
- {
- if (ps == NULL) return 0;
- memset(ps, 0, sizeof(BODY));
- fflush(stdin);
- printf("nEnter delivery number: ");
- scanf("%d", &(ps->num));
- fflush(stdin);
- printf("nEnter name of product: ");
- gets(ps->name);
- printf("nEnter provider code: ");
- gets(ps->code);
- printf("nEnter provider's company, address and phone number: ");
- gets(ps->info);
- printf("nEnter date: ");
- scanf("%d", &(ps->day));
- fflush(stdin);
- printf("nEnter month: ");
- scanf("%d", &(ps->month));
- fflush(stdin);
- printf("nEnter year: ");
- scanf("%d", &(ps->year));
- fflush(stdin);
- printf("nEnter amount delivered: ");
- scanf("%d", &(ps->amount));
- fflush(stdin);
- return 1;
- }
- void printBody(BODY s)
- {
- printf("nNumber: %dtName: %stCode: %stInfo: %snDate: %d-%d-%dtAmount: %d",
- s.num, s.name, s.code, s.info, s.day, s.month, s.year, s.amount);;
- }
- void printList(LIST*pFirst, int pm, int py)
- {
- LIST*p = NULL;
- if(strcmp(p->body.month, pm) == 0)
- p = pFirst;
- while (p != NULL)
- {
- printBody(p->body);
- p = p->pNext;
- }
- printf("n");
- }
- LIST*insertBegin(LIST*pFirst, BODY newBody)
- {
- LIST*p;
- p = (LIST*)malloc(sizeof(LIST));
- if (p == NULL)
- {
- printf("Not enough memoryn");
- return NULL;
- }
- else
- {
- p->body = newBody;
- p->pNext = pFirst;
- pFirst = p;
- return p;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement