fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. //**************************************************************
  5. // Function: isLegal
  6. //
  7. // Purpose: Determine if a given word is legal
  8. //
  9. // Parameters:
  10. //
  11. // theString - string/word that determining if legal or not
  12. //
  13. // Returns: whether legal (1=legal, 0=not legal)
  14. //
  15. //**************************************************************
  16.  
  17. int isLegal (char theString[]){
  18. char vowels[]={'a','e','i','o','u','y','A','E','I','O','U','Y'};
  19.  
  20. int numVowels=0; //initializing the variable that will hold the number of vowels
  21. for (int i=0; theString[i]!='\0';i++){ //looping through the characters in the string being searched
  22. // for (int j=0; j<strlen(vowels);j++){
  23. // if (theString[i]==vowels[j]){
  24. // numVowels+=1;
  25. // }
  26. numVowels+=1;
  27. }
  28. return numVowels;
  29. }
  30. int main() {
  31. int numVowels= isLegal("try");
  32. printf("Number of vowels: %i\n", numVowels);
  33. return 0;
  34. };
  35.  
  36.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Number of vowels: 3