C Program to Find Consecutive Occurrence of Vowel in a String

This C Program finds words having consecutive occurrence of any vowel in a string.

Here is a source code of the C program to find the words with consecutive occurrence of any vowel in a string. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C Program to Find the Consecutive Occurrence of any Vowel
  3.  * in a String
  4.  */
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <ctype.h>
  8.  
  9. struct detail
  10. {
  11.     char word[20];
  12. };
  13.  
  14. int update(struct detail [], const char [], int);
  15. int vowelcheck(char);
  16.  
  17. int main()
  18. {
  19.     struct detail s[10];
  20.     char string[100], unit[20], c;
  21.     int i = 0, j = 0, count = 0;
  22.  
  23.     printf("Enter string: ");
  24.     i = 0;
  25.     do
  26.     {
  27.         fflush(stdin);
  28.         c = getchar();
  29.         string[i++] = c;
  30.  
  31.     } while (c != '\n');
  32.     string[i - 1] = '\0';
  33.     printf("The string entered is: %s\n", string);
  34.     for (i = 0; i < strlen(string); i++)
  35.     {
  36.         while (i < strlen(string) && string[i] != ' ' && isalnum(string[i]))
  37.         {
  38.             unit[j++] = string[i++];
  39.         }
  40.         if (j != 0)
  41.         {
  42.             unit[j] = '\0';
  43.             count = update(s, unit, count);
  44.             j = 0;
  45.         }
  46.     }
  47.  
  48.     printf("**Words with consecutive vowel**\n");
  49.     for (i = 0; i < count; i++)
  50.     {
  51.         printf("%s\n", s[i].word);
  52.     }
  53.  
  54.     return 0;
  55. }
  56.  
  57. int update(struct detail s[], const char unit[], int count)
  58. {
  59.     int i, j = 0;
  60.  
  61.     for (i = 0; i < strlen(unit) - 1; i++)
  62.     {
  63.         if (vowelcheck(unit[i]))
  64.         {
  65.             if (vowelcheck(unit[i+ 1]))
  66.             {
  67.                 /*To avoid duplicate strings*/
  68.                 while (j < count && strcmp(s[j].word, unit))
  69.                 {
  70.                     j++;
  71.                 }
  72.                 if (j == count)
  73.                 {
  74.                     strcpy(s[j].word, unit);
  75.  
  76.                     return (count + 1);
  77.                 }
  78.             }
  79.         }
  80.     }
  81.  
  82.     return count;
  83. }
  84.  
  85. int vowelcheck(char c)
  86. {
  87.     char vowel[5] = {'a', 'e', 'i', 'o', 'u'};
  88.     int i;
  89.  
  90.     c = tolower(c);
  91.     for (i = 0; i < 5; i++)
  92.     {
  93.         if (c == vowel[i])
  94.         {
  95.             return 1;
  96.         }
  97.     }
  98.  
  99.     return 0;
  100. }

$ gcc consecutivevowel.c 
$ ./a.out
Enter string: Who will lead his team to victory
The string entered is: Who will lead his team to victory
**Words with consecutive vowel**
lead
team

Sanfoundry Global Education & Learning Series – 1000 C Programs.

advertisement
advertisement

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

If you wish to look at programming examples on all topics, go to C Programming Examples.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.