Advertisement
Guest User

Untitled

a guest
May 24th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<malloc.h>
  5. #define MAX_LENGTH 80
  6. #define LOOPS 1
  7. struct delivery
  8. {
  9. int num;
  10. char name[20];
  11. char code[8];
  12. char info[80];
  13. int day;
  14. int month;
  15. int year;
  16. int amount;
  17. };
  18. typedef struct delivery BODY;
  19. struct List{
  20. BODY body;
  21. struct List*pNext;
  22. };
  23. typedef struct List LIST;
  24. int enterBody(BODY*ps);
  25. void printBody(BODY s);
  26. void printList(LIST*pFirst, int pm, int py);
  27. LIST*insertBegin(LIST*pFirst, BODY newBody);
  28.  
  29. int main()
  30. {
  31. FILE*pOut = NULL, *pIn = NULL;
  32. char Fname[] = "List_bin.dat";
  33. BODY newbody;
  34. LIST*pFirst = NULL, *p;
  35. int res, i, mode, pm, py;
  36. char sfn[20], gr[20];
  37. int newgr, fn;
  38. BODY delivery;
  39. char*menu[] = { "MENU:",
  40. "1 - Enter info for new delivery ",
  41. "2 - Print info for deliveries for an entered month ",
  42. };
  43. do
  44. {
  45. system("cls");
  46. for (i = 0; i < 3; i++)
  47. printf("n%sn", menu[i]);
  48. do
  49. {
  50. fflush(stdin);
  51. printf("nChoose operation (1-2): ");
  52. res = scanf("%d", &mode);
  53. } while (res != 1);
  54. switch (mode)
  55. {
  56. case 1:
  57. for (i = 0; i < LOOPS; i++)
  58. {
  59. res = enterBody(&delivery);
  60. if (res != 1)
  61. {
  62. printf("Error in initialization %dn", res);
  63. break;
  64. }
  65. p = insertBegin(pFirst, delivery);
  66. if (p == NULL)
  67. {
  68. printf("Not enough memory! ");
  69. break;
  70. }
  71. pFirst = p;
  72. }
  73. system("pause");
  74. break;
  75. case 2:
  76. printf("nEnter month: ");
  77. scanf("%19s", pm);
  78. printf("nEnter year: ");
  79. scanf("%19s", py);
  80. if (pFirst != NULL)
  81. {
  82. printList(pFirst, pm, py);
  83. }
  84. else printf("nEmpty list!n");
  85. system("pause");
  86. break;
  87.  
  88. default:
  89. printf("nIncorrect operation!n");
  90. system("pause");
  91. }
  92. } while (mode != 11);
  93. system("pause");
  94. return 0;
  95. }
  96.  
  97. int enterBody(BODY*ps)
  98. {
  99. if (ps == NULL) return 0;
  100. memset(ps, 0, sizeof(BODY));
  101. fflush(stdin);
  102. printf("nEnter delivery number: ");
  103. scanf("%d", &(ps->num));
  104. fflush(stdin);
  105. printf("nEnter name of product: ");
  106. gets(ps->name);
  107. printf("nEnter provider code: ");
  108. gets(ps->code);
  109. printf("nEnter provider's company, address and phone number: ");
  110. gets(ps->info);
  111. printf("nEnter date: ");
  112. scanf("%d", &(ps->day));
  113. fflush(stdin);
  114. printf("nEnter month: ");
  115. scanf("%d", &(ps->month));
  116. fflush(stdin);
  117. printf("nEnter year: ");
  118. scanf("%d", &(ps->year));
  119. fflush(stdin);
  120. printf("nEnter amount delivered: ");
  121. scanf("%d", &(ps->amount));
  122. fflush(stdin);
  123. return 1;
  124. }
  125.  
  126. void printBody(BODY s)
  127. {
  128. printf("nNumber: %dtName: %stCode: %stInfo: %snDate: %d-%d-%dtAmount: %d",
  129. s.num, s.name, s.code, s.info, s.day, s.month, s.year, s.amount);;
  130. }
  131.  
  132. void printList(LIST*pFirst, int pm, int py)
  133. {
  134. LIST*p = NULL;
  135.  
  136. if(strcmp(p->body.month, pm) == 0)
  137. p = pFirst;
  138. while (p != NULL)
  139. {
  140. printBody(p->body);
  141. p = p->pNext;
  142. }
  143. printf("n");
  144. }
  145.  
  146. LIST*insertBegin(LIST*pFirst, BODY newBody)
  147. {
  148. LIST*p;
  149. p = (LIST*)malloc(sizeof(LIST));
  150. if (p == NULL)
  151. {
  152. printf("Not enough memoryn");
  153. return NULL;
  154. }
  155. else
  156. {
  157. p->body = newBody;
  158. p->pNext = pFirst;
  159. pFirst = p;
  160. return p;
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement