Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char vowel[] = "aeyuioAEYUIO";
- int vowelLength = strlen(vowel);
- count = 0;
- int neededWord = 0; // bool variable that shows if the word has two vowels in a row
- int startIndx = -1; // stores an index of first letter of a word
- int wordStarted = 0; // bool variable to indicate if startIndx stores an indx
- for (int i = 0; i < size; i++)
- {
- if (isalpha(buffer[i]))
- {
- for (int j = 0; j < vowelLength; j++)
- {
- if (buffer[i] == vowel[j])
- {
- for (int j = 0; j < vowelLength; j++)
- {
- if (buffer[i + 1] == vowel[j])
- {
- neededWord = 1;
- count++;
- break;
- }
- }
- break;
- }
- }
- }
- else
- {
- // if char isn't alphabetical - then check next char
- // if next char is alphabetical - it's the beginning of a word
- int justStarted = 0;
- if (isalpha(buffer[i + 1]))
- {
- // change bool var and assign index of 1st letter of a word
- // to specialized var
- if (wordStarted == 0)
- {
- justStarted = 1;
- wordStarted = 1;
- startIndx = i + 1;
- }
- }
- if (wordStarted == 1 && !justStarted)
- {
- // wordStarted == 1 means that we already have an index of
- // the beginning of a word. And the end of the word is current i.
- // we change back bool variable to 0 & print found word
- wordStarted = 0;
- if (neededWord == 1)
- {
- for (int k = startIndx; k < i; k++){
- printf("%c", buffer[k]);
- }
- printf(", ");
- neededWord = 0;
- }
- }
- }
- }
- printf("\nNumber of words: %i.\n", count);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement