snowden_web

Untitled

May 30th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1.  
  2.     char str[1000];
  3.     printf("Enter the text\n");
  4.     fflush(stdin);
  5.     fgets(str, sizeof(str), stdin);
  6.     // создание массива слов
  7.     char **words = NULL, *p = NULL;
  8.     int i, cnt = 0;
  9.  
  10.     for (p = strtok(str, " "); p != NULL; p = strtok(NULL, " ")) {
  11.         if ((words = (char **) realloc(words, sizeof(char *) * (cnt + 1))) == NULL) {
  12.             printf("No memory to new word!\n");
  13.             exit(1);
  14.         }
  15.         if ((words[cnt] = strdup(p)) == NULL) {
  16.             printf("Can't duplicate word!\n");
  17.             exit(1);
  18.         }
  19.         ++cnt;
  20.     }
  21.  
  22.     // подсчет гласных в словах
  23.     for (i = 0; i < cnt; ++i) {
  24.         if (count_of_vowels(words[i]) < 3) printf("%s ", words[i]);
  25.     }
  26.  
  27.  
  28.     for (i = 0; i < cnt; ++i) {
  29.         if (words[i] != NULL) {
  30.             free(words[i]);
  31.             words[i] = NULL;
  32.         }
  33.     }
  34.     free(words);
  35.     words = NULL;
  36.     printf("\n\n");
Add Comment
Please, Sign In to add comment