fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <locale.h>
  4. #include <stdio.h>
  5. struct city
  6. {
  7. char name_f[80];
  8. char name_p[80];
  9. char date[80];
  10. char genre[80];
  11. struct city *next;
  12. struct city *previous;
  13. };
  14. struct city *head=NULL;
  15. struct city *last=NULL;
  16. struct city *current=NULL; //òåêóùèé ýëåìåíò
  17. struct city *temp=NULL;
  18. struct city *newList=NULL ;
  19. /* Ïðîöåäóðà ñîçäàíèÿ äîáàâëåíèÿ â ñïèñîê */
  20. void add_name(char namef_,char namep_, int date_, char genre_)
  21. {
  22. /* if(head!=NULL)
  23.   {
  24.   */ newList=(struct city*)malloc (sizeof(struct city));
  25. newList->name_f,namef_;
  26. newList->name_p,namep_;
  27. newList->date,date_;
  28. newList->genre,genre_;
  29. newList->next=head;
  30. newList->previous=NULL;
  31. head=newList;
  32. /* current=newList;
  33.   }
  34.   else
  35.   {
  36.   newList=malloc (sizeof(struct city));
  37.   strcpy(newList->name_f,namef_);
  38.   strcpy(newList->name_p,namep_);
  39.   strcpy(newList->date,date_);
  40.   strcpy(newList->genre,genre_);
  41.   strcpy(head,newList);
  42.   strcpy(newList->next,NULL);
  43.   strcpy(newList->previous,NULL);
  44.   current=newList;
  45.   */ if(last==NULL) last=head;
  46.  
  47. //}
  48.  
  49. /* Ïðîöåäóðà óäàëåíèÿ ïåðâîãî óçëà */
  50. void delete_unit()
  51. { newList=head;
  52. if(newList != NULL) //åñëè ñïèñîê íå ïóñòîé
  53. {
  54. head=head->next;
  55. free(newList); //óäàëåíèå ýëåìåíòà
  56. if (head!=NULL) //ýëåìåíò íå åäèíñòâåííûé
  57. head->previous=NULL;
  58. else //óäàëèëè åäèíñòâåííûé, ñïèñîê ñòàë ïóñòûì
  59. last = NULL;
  60. }
  61. /*else
  62. {
  63.   head=head->next;
  64.   head->previous=NULL;
  65. free(newList);
  66. }*/
  67. }
  68. int count_L()/*ïîäñ÷åò ÷èñëà ýëåìåíòîâ â ñïèñêå*/
  69. {
  70. int count=0;
  71. newList = head;
  72. /*if(newList == NULL)
  73. {
  74. count = 0;
  75. }
  76. else
  77. {*/
  78. while(newList != NULL)
  79. {
  80. count=count+1;
  81. newList = newList->next;
  82. }
  83. /* }*/
  84. return count;
  85. }
  86. /* Ïðîöåäóðà âûâîäà ñïèñêà ñëåâà íàïðàâî */
  87. void show_list(void)
  88. {
  89. struct city *info;
  90. info = head;
  91. while(info)
  92. {
  93.  
  94. printf("%s", info->name_f);
  95. printf("%s", info->name_p);
  96. printf("%d", info->date);
  97. printf("%s", info->genre);
  98. printf("\n");
  99. info = info->next;
  100. }
  101. }
  102. /* Ïðîöåäóðà âûâîäà ñïèñêà ñïðàâà íàëåâî */
  103. void show_list_1(void)
  104. {
  105. struct city *info;
  106. info = last;
  107. while(info)
  108. {
  109. printf("%s\n", info->name_f);
  110. printf("%s\n", info->name_p);
  111. printf("%d\n", info->date);
  112. printf("%s\n", info->genre);
  113. printf("\n");
  114. info=info->previous;
  115. }
  116. }
  117.  
  118. /* Òåëî îñíîâíîé ïðîãðàììû */
  119. int main(void)
  120. {
  121. setlocale(LC_ALL,"Russian");
  122. SetConsoleCP(1251);
  123. SetConsoleOutputCP(1251);
  124. char name_f;
  125. char name_p;
  126. int date;
  127. char genre;
  128. int key=-1;
  129. while(key)
  130. {
  131. printf("1. Enter name\n");
  132. printf("2. Delete name\n");
  133. printf("3. Show names\n");
  134. printf("4. Show names from end\n");
  135. printf("0. Exit\n");
  136. scanf("%d", &key);
  137. switch (key)
  138. {
  139. case 1:
  140. {
  141. printf("Ââåäèòå íàçâàíèå òåàòðà\n");
  142. gets(name_f);
  143. printf("Âåäèòå íàçâàíèå ïðåäñòàâëåíèÿ\n");
  144. gets(name_p);
  145. printf("Âåäèòå äàòó ïðåäñòàâëåíèÿ\n");
  146. gets(date);
  147. printf("Âåäèòå æàíð ïðåäñòàâëåíèÿ\n");
  148. gets(genre);
  149. add_name(name_f,name_p,date,genre);
  150. break;
  151. }
  152. case 2:
  153. {
  154. int n = count_L();
  155. if(n == 0)
  156. {
  157. printf("Íåâîçìîæíîó óäàëèòü ýëåìåíòû â ñòåêå 0 ýëåìåíòîâ");
  158. }
  159. else if (n == 1)
  160. {
  161. printf("Íåâîçìîæíîó óäàëèòü ýëåìåíòû â ñòåêå 1 ýëåìåíò");
  162. }
  163. else if (n > 2)
  164. {
  165. delete_unit();
  166. delete_unit();
  167. }
  168. break;
  169. }
  170. case 3:
  171. {
  172. printf("Ñïèñîê ñëåâà íàïðàâî\n");
  173. show_list();
  174. break;
  175. }
  176. case 4:
  177. {
  178. printf("Ñïèñîê ñ ïðàâà íà ëåâî\n");
  179. show_list_1();
  180. break;
  181. }
  182. case 0:
  183. {
  184. printf("Ïîêà\n");
  185. getch();
  186. return;
  187. }
  188. default:
  189. {
  190. printf("Error\n");
  191. getch();
  192. break;
  193. }
  194. if (key==0) break;
  195. }
  196. }
  197. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘add_name’:
prog.c:25:24: warning: left-hand operand of comma expression has no effect [-Wunused-value]
         newList->name_f,namef_;
                        ^
prog.c:25:9: warning: statement with no effect [-Wunused-value]
         newList->name_f,namef_;
         ^
prog.c:26:24: warning: left-hand operand of comma expression has no effect [-Wunused-value]
         newList->name_p,namep_;
                        ^
prog.c:26:9: warning: statement with no effect [-Wunused-value]
         newList->name_p,namep_;
         ^
prog.c:27:22: warning: left-hand operand of comma expression has no effect [-Wunused-value]
         newList->date,date_;
                      ^
prog.c:27:9: warning: statement with no effect [-Wunused-value]
         newList->date,date_;
         ^
prog.c:28:23: warning: left-hand operand of comma expression has no effect [-Wunused-value]
         newList->genre,genre_;
                       ^
prog.c:28:9: warning: statement with no effect [-Wunused-value]
         newList->genre,genre_;
         ^
prog.c: In function ‘show_list’:
prog.c:96:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=]
     printf("%d", info->date);
     ^
prog.c: In function ‘show_list_1’:
prog.c:111:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=]
     printf("%d\n", info->date);
     ^
prog.c: In function ‘add_name’:
prog.c:119:5: warning: ‘main’ is normally a non-static function [-Wmain]
 int main(void)
     ^
prog.c: In function ‘main’:
prog.c:122:5: warning: implicit declaration of function ‘SetConsoleCP’ [-Wimplicit-function-declaration]
     SetConsoleCP(1251);
     ^
prog.c:123:2: warning: implicit declaration of function ‘SetConsoleOutputCP’ [-Wimplicit-function-declaration]
  SetConsoleOutputCP(1251);
  ^
prog.c:142:29: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
                             gets(name_f);
                             ^
prog.c:142:29: warning: passing argument 1 of ‘gets’ makes pointer from integer without a cast [enabled by default]
In file included from prog.c:1:0:
/usr/include/stdio.h:638:14: note: expected ‘char *’ but argument is of type ‘char’
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
prog.c:144:29: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
                             gets(name_p);
                             ^
prog.c:144:29: warning: passing argument 1 of ‘gets’ makes pointer from integer without a cast [enabled by default]
In file included from prog.c:1:0:
/usr/include/stdio.h:638:14: note: expected ‘char *’ but argument is of type ‘char’
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
prog.c:146:8: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
        gets(date);
        ^
prog.c:146:8: warning: passing argument 1 of ‘gets’ makes pointer from integer without a cast [enabled by default]
In file included from prog.c:1:0:
/usr/include/stdio.h:638:14: note: expected ‘char *’ but argument is of type ‘int’
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
prog.c:148:8: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
        gets(genre);
        ^
prog.c:148:8: warning: passing argument 1 of ‘gets’ makes pointer from integer without a cast [enabled by default]
In file included from prog.c:1:0:
/usr/include/stdio.h:638:14: note: expected ‘char *’ but argument is of type ‘char’
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
prog.c:185:29: warning: implicit declaration of function ‘getch’ [-Wimplicit-function-declaration]
                             getch();
                             ^
prog.c:186:29: warning: ‘return’ with no value, in function returning non-void [-Wreturn-type]
                             return;
                             ^
prog.c: In function ‘add_name’:
prog.c:197:1: error: expected declaration or statement at end of input
 }
 ^
stdout
Standard output is empty