Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would write a function to find syllables in a string in c? function prototyp

ID: 3792587 • Letter: H

Question

How would write a function to find syllables in a string in c?

function prototype:

int countSyllables (char string);

Also, numbers would count as one syllable.

Count all syllables in each word. To make this simple, use the following rules: Each group of adjacent vowels (a, e, i, o, u, y) counts as one syllable (for example, the "ea" in "real" counts as one syllable, but the "e..a in "regal" count as two syllables). However, an "e" at the end of a word does not count as a syllable. Each word has at least one syllable even if the previous rules give a count of zero.

Explanation / Answer

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int isVowel(char x) {
  
   if( x =='a' || x =='e' || x =='i' || x =='o' || x =='u') {
       return 1;
   }

   return 0;
}

int countSylabbles (char str[]){

   int len = strlen(str);
   int count = 0;
   int i = 0;
   while(i < len) {
       //check if vowel and not the last character of the string
       if (isVowel(str[i]) && i != (len -1)) {
           i++;
           while(isVowel(str[i]) && i < len) {
               i++;
           }
           count += 1;
       } else if(isdigit(str[i])) {
           count++;
           i++;
       } else {
           i++;
       }
   }
   return count;
}

int main() {
   // your code goes here
   printf("%d", countSylabbles("Thischeckssyl1aablese"));
   return 0;
}

Output

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote