Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.18 KB | None | 0 0
  1. char vowel[] = "aeyuioAEYUIO";
  2.     int vowelLength = strlen(vowel);
  3.     count = 0;
  4.     int neededWord = 0;  // bool variable that shows if the word has two vowels in a row
  5.     int startIndx = -1;  // stores an index of first letter of a word
  6.     int wordStarted = 0; // bool variable to indicate if startIndx stores an indx
  7.     for (int i = 0; i < size; i++)
  8.     {
  9.         if (isalpha(buffer[i]))
  10.         {
  11.             for (int j = 0; j < vowelLength; j++)
  12.             {
  13.                 if (buffer[i] == vowel[j])
  14.                 {
  15.                     for (int j = 0; j < vowelLength; j++)
  16.                     {
  17.                         if (buffer[i + 1] == vowel[j])
  18.                         {
  19.                             neededWord = 1;
  20.                             count++;
  21.                             break;
  22.                         }
  23.                     }
  24.                     break;
  25.                 }
  26.             }
  27.         }
  28.         else
  29.         {
  30.             // if char isn't alphabetical - then check next char
  31.             // if next char is alphabetical - it's the beginning of a word
  32.             int justStarted = 0;
  33.             if (isalpha(buffer[i + 1]))
  34.             {
  35.                 // change bool var and assign index of 1st letter of a word
  36.                 // to specialized var
  37.                 if (wordStarted == 0)
  38.                 {
  39.                     justStarted = 1;
  40.                     wordStarted = 1;
  41.                     startIndx = i + 1;
  42.                 }
  43.             }
  44.             if (wordStarted == 1 && !justStarted)
  45.             {
  46.                 // wordStarted == 1 means that we already have an index of
  47.                 // the beginning of a word. And the end of the word is current i.
  48.                 // we change back bool variable to 0 & print found word
  49.  
  50.                 wordStarted = 0;
  51.                 if (neededWord == 1)
  52.                 {
  53.                     for (int k = startIndx; k < i; k++){
  54.                         printf("%c", buffer[k]);
  55.                     }  
  56.                     printf(", ");
  57.                     neededWord = 0;
  58.                 }
  59.             }
  60.         }
  61.     }
  62.     printf("\nNumber of words: %i.\n", count);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement