fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int isLegal(char theString[]);
  5.  
  6. int main(void) {
  7. char word[50];
  8. printf("Enter word: ");
  9. scanf("%49s", word);
  10.  
  11. if (isLegal(word)) {
  12. printf("%s is legal\n", word);
  13. } else {
  14. printf("%s is illegal\n", word);
  15. }
  16. return 0;
  17. }
  18.  
  19. int isLegal(char theString[]) {
  20. int legal = 0;
  21. const char vowels[] = "AEIOUY";
  22.  
  23. for (int i = 0; theString[i] != '\0'; i++) {
  24. char c = toupper((unsigned char)theString[i]);
  25.  
  26. // check against vowels
  27. for (int j = 0; vowels[j] != '\0'; j++) {
  28. if (c == vowels[j]) {
  29. legal = 1;
  30. return legal; // we can stop as soon as we find a vowel
  31. }
  32. }
  33. }
  34. return legal;
  35. }
Success #stdin #stdout 0s 5320KB
stdin
bvf
stdout
Enter word: bvf is illegal