fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5. #include <stdlib.h>
  6. #include <Windows.h>
  7. #include <conio.h>
  8. #include <locale.h>
  9. #include <memory.h>
  10.  
  11. struct Note
  12. {
  13. char name[100];
  14. char number[10];
  15. int birthday[3];
  16. };
  17.  
  18. struct node {
  19. struct Note person;
  20. struct node* next;
  21. };
  22. int validation_int(int n, int p);
  23. void get_information(struct Note *people);
  24. void print_information(struct Note people);
  25. void sort_notes(struct Note* people);
  26. void print_list(struct node* people);
  27. struct node* add_elem(struct node* root, struct Note person);
  28.  
  29.  
  30. int main() {
  31. setlocale(LC_ALL, "rus");
  32. SetConsoleOutputCP(1251);
  33. SetConsoleCP(1251);
  34.  
  35.  
  36. int month, i, flag = 0;
  37. struct Note list_notes[5];
  38. struct node* nodes;
  39. printf_s("Введення інформації про людей:\n");
  40. for (i = 0; i < 2; i++) {
  41. get_information(&list_notes[i]);
  42. nodes = add_elem(nodes, list_notes[i]);
  43. //print_list(nodes);
  44. }
  45. /*sort_notes(nodes);*/
  46. print_list(nodes);
  47. int op;
  48. printf_s("Оберіть необхідну операцію: ");
  49. scanf_s("%d", &op);
  50.  
  51. switch (op) {
  52. case 1: {
  53. printf("Введіть значення місяця: ");
  54. month = validation_int(12, 1);
  55. while (nodes->next) {
  56. if (nodes->person.birthday[1] == month) {
  57. print_information(list_notes[i]);
  58. flag = 1;
  59. }
  60. }
  61. if (!flag) {
  62. printf("У вказаному місяці не нaрoдилось людей зі списку");
  63. }
  64. _getche();
  65. system("cls");
  66. return main();
  67. }
  68. case 2: {
  69. return 0;
  70. }
  71. }
  72.  
  73.  
  74. }
  75.  
  76.  
  77. int validation_int(int n, int p) {
  78. int number = 0, len = 0, minus = 0;
  79. char* string;
  80.  
  81. string = (char*)malloc(100 * sizeof(char));
  82. gets(string);
  83. len = strlen(string);
  84. if (string[0] == '-' && !p)
  85. minus = 1;
  86. int j = minus;
  87. for (j; j < len; j++) {
  88. if (isdigit(string[j])) {
  89. number += ((int)string[j] - 48) * pow(10, len - j - 1);
  90. }
  91. else {
  92. printf("Не коректний ввід. Спробуй ще:\n");
  93. return validation_int(n, p);
  94. }
  95. }
  96. if (!minus) {
  97. if (number > n && n != 0) {
  98. printf("Не коректний ввід. Спробуй ще:\n");
  99. return validation_int(n, p);
  100. }
  101. else
  102. return number;
  103. }
  104. else
  105. return number *= -1;
  106. }
  107. void get_information(struct Note *person) {
  108. printf("Введіть інформацію про людину:\n");
  109. printf("Введіть ім'я: ");
  110. gets(person->name);
  111. /*person.number = (char*)malloc(20 * sizeof(char));*/
  112. printf("Введіть номер телефону: ");
  113. gets(person->number);
  114. printf("Введіть день у який народилась людина: ");
  115. person->birthday[0] = validation_int(31, 1);
  116. printf("Введіть місяць у який народилась людина: ");
  117. person->birthday[1] = validation_int(12, 1);
  118. printf("Введіть рік народження людини: ");
  119. person->birthday[2] = validation_int(2019, 1);
  120. printf("\n\n");
  121.  
  122. }
  123. struct node* add_elem(struct node* root, struct Note person) {
  124. if (!root) {
  125. struct node* tmp = malloc(sizeof(struct node));
  126. tmp->person = person;
  127. tmp->next = NULL;
  128. return tmp;
  129. }
  130. struct node * p = root;
  131. while (p->next) p = p->next;
  132. struct node* tmp = malloc(sizeof(struct node));
  133. tmp->person = person;
  134. tmp->next = NULL;
  135. p->next = tmp;
  136. return root;
  137. }
  138. void print_information(struct Note person) {
  139. printf("Ім'я: %s\n", person.name);
  140. printf("Номер телефона: ");
  141. int l = strlen(person.number);
  142. for (int i = 0; i < l; i++)
  143. printf("%c", person.number[i]);
  144. printf("\n");
  145. printf("Дата народження: ");
  146. for (int i = 0; i < 3; i++)
  147. printf_s("%d. ", person.birthday[i]);
  148. printf("...........................................................................................");
  149. }
  150. void sort_notes(struct node* root) {
  151. struct Note person;
  152. for (int i = 0; i < 5; i++) {
  153. for (int j = 0; j < 4 - i; j++) {
  154. if ((int)tolower(root[j].person.name[0]) > (int)tolower(root[j+1].person.name[0])) {
  155. person = root[j].person;
  156. root[j].person = root[j+1].person;
  157. root[j+1].person = person;
  158. }
  159. }
  160. }
  161. }
  162.  
  163. void print_list(struct node* people) {
  164. printf("Ім'я\t\tНомер телефона\t\tДата народження\n\n");
  165. printf(".............................................................................");
  166. if (!people) {
  167. printf("Error\n");
  168. return;
  169. }
  170. do{
  171. printf("%s\t%s\t%d.%d.%d", people->person.name, people->person.number, people->person.birthday[0],
  172. people->person.birthday[1], people->person.birthday[2]);
  173. printf("..........................................................................");
  174. people = people->next;
  175. } while (people);
  176. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
a
1
1
1
1
b
2
2
2
2
compilation info
prog.c:6:21: fatal error: Windows.h: No such file or directory
 #include <Windows.h>
                     ^
compilation terminated.
stdout
Standard output is empty