Advertisement
Asmund_11

Untitled

Nov 26th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #define SIZE 200
  6. typedef struct List {
  7.     char* rech;
  8.     struct List* next, * prev;
  9. } LIST;
  10. LIST* head = NULL;
  11.  
  12. void Input(LIST* p);
  13. void AddElem(pnew);
  14. void PrintList();
  15.  
  16. int main()
  17. {
  18.     Input(head);
  19.     PrintList();
  20.     return 0;
  21. }
  22.  
  23. void Input(LIST* p)
  24. {
  25.     char buf[SIZE] = { "" };
  26.     A:
  27.     p = (LIST*)malloc(sizeof(LIST));
  28.     if (head == NULL) {
  29.         p->prev = p->next = NULL;
  30.         head = p;
  31.     }
  32.     if (*gets_s(buf, SIZE) != '\0') {
  33.         fflush(stdin);
  34.         gets(buf);
  35.         p->rech = (char*)malloc(strlen(buf) + 1);
  36.         strcpy(p->rech, buf);
  37.         AddElem(p);
  38.         goto A;
  39.     }
  40.     else {
  41.         return;
  42.     }
  43. }
  44.  
  45. void AddElem(LIST* pnew)
  46. {
  47.     head->prev = pnew;
  48.     pnew->next = head;
  49.     pnew->prev = NULL;
  50.     head = pnew;
  51.     return;
  52. }
  53.  
  54. void PrintList()
  55. {
  56.     LIST* p = head;
  57.     printf("%s", p->rech);
  58.     /*while (p != NULL) {
  59.         printf("\n%s", p->rech);
  60.         p = p->next;
  61.     }*/
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement