Advertisement
Asmund_11

Untitled

Nov 21st, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 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.  
  7. typedef struct List {
  8.     char* rech;
  9.     struct List* next, * prev;
  10. } LIST;
  11. LIST *head;
  12.  
  13. void Input(LIST* p);
  14. void AddElem(LIST *pnew, LIST *pold);
  15. void PrintList(void);
  16. void Func(char rech[], char letter);
  17.  
  18. int main()
  19. {
  20.     system("chcp 1251");
  21.     char letter;
  22.     printf("Введіть букву: ");
  23.     scanf_s("%c", &letter);
  24.     scanf_s("%*c");
  25.     puts("Введіть речення:");
  26.     LIST input;
  27.     Input(&input);
  28.     PrintList();
  29.     return 0;
  30. }
  31.  
  32. void Input(LIST* p)
  33. {
  34.     char buf[SIZE] = { "" };
  35.     A:
  36.     p = (LIST*)malloc(sizeof(LIST));
  37.     if (head == NULL) {
  38.         p->prev = p->next = NULL;
  39.         head = p;
  40.     }
  41.     if (*gets_s(buf, SIZE) != '\0') {
  42.         fflush(stdin);
  43.         gets(buf);
  44.         p->rech = (char*)malloc(strlen(buf) + 1);
  45.         strcpy(p->rech, buf);
  46.         AddElem(p, head);
  47.         goto A;
  48.     }
  49.     else
  50.         return;
  51. }
  52.  
  53. void AddElem(LIST* pnew, LIST* pold)
  54. {
  55.     head->prev = pnew;
  56.     pnew->next = head;
  57.     pnew->prev = NULL;
  58.     head = pnew;
  59.     return;
  60. }
  61.  
  62. void PrintList(void)
  63. {
  64.     LIST* p = head;
  65.     printf("%s", p->rech);
  66.     /*while (p != NULL) {
  67.         printf("\n%s", p->rech);
  68.         p = p->next;
  69.     }*/
  70. }
  71.  
  72. void Func(char rech[], char letter)
  73. {
  74.     char* p = strtok(rech, " ");
  75.     while (p != NULL) {
  76.         for (int i = 0; i < strlen(p); i++) {
  77.             if (p[i] == letter) {
  78.                 for (int i = 0; i < strlen(p); i++)
  79.                     p[i] = '*';
  80.                 goto A;
  81.             }
  82.         }
  83.         A:
  84.         printf("%s ", p);
  85.         p = strtok(NULL, " ");
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement