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++){ //looping through the list of vowels in the vowels array
  23. if (theString[i]==vowels[j]){ //checking if the current character from theString (i.e., the one associated with the current iteration of the outer loop) is equal to the vowel (i.e. the current value in the inner loop)
  24. numVowels+=1;
  25. }
  26. }
  27. }
  28. int legal=0;
  29. if (numVowels>=1){
  30. legal=1; //if at least 1 vowel, then word is legal
  31. }
  32. return legal;
  33. }
  34. int main() {
  35. int legalYN= isLegal("try");
  36. printf("Is legal, 1=yes, 2=no: %i\n", legalYN);
  37. return 0;
  38. };
  39.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
Is legal, 1=yes, 2=no: 1