#include <stdio.h>
#include <ctype.h>
/**
* Function: isLegal
* -----------------
* Determines if a given word is "legal" based on the presence of vowels.
* For this problem, the letter 'Y' is considered a vowel.
*
* Rules:
* - A word is illegal if it contains no vowels (a, e, i, o, u, y).
* - Case does not matter (uppercase and lowercase are treated the same).
* - The input string is assumed to contain only letters and is null terminated.
*
* Parameters:
* inputWord[] - a null-terminated string consisting of letters only
*
* Returns:
* 1 if the word is legal (contains at least one vowel),
* 0 if the word is illegal (contains no vowels).
*/
int isLegal(char inputWord[]) {
// Local variable to track current index in the string
int stringIndex = 0;
// Local variable to hold the current character being checked
char currentCharacter;
// Loop through each character in the string until null terminator is reached
while (inputWord[stringIndex] != '\0') {
// Assign the current character
currentCharacter = inputWord[stringIndex];
// Convert to lowercase for uniform comparison
currentCharacter
= tolower(currentCharacter
);
// Check if the current character is a vowel (including 'y')
if (currentCharacter == 'a' ||
currentCharacter == 'e' ||
currentCharacter == 'i' ||
currentCharacter == 'o' ||
currentCharacter == 'u' ||
currentCharacter == 'y') {
// Found a vowel → word is legal
return 1;
}
// Move to the next character in the string
stringIndex = stringIndex + 1;
}
// If loop completes without finding a vowel → word is illegal
return 0;
}
/**
* Function: main
* --------------
* Entry point of the program. Tests the isLegal function
* with several example words.
*/
int main(void) {
// Test word 1: "sch" → illegal
char testWord1[] = "sch";
printf("%s -> %s\n", testWord1
, isLegal
(testWord1
) ? "legal" : "illegal");
// Test word 2: "apple" → legal
char testWord2[] = "apple";
printf("%s -> %s\n", testWord2
, isLegal
(testWord2
) ? "legal" : "illegal");
// Test word 3: "APPle" → legal (case insensitive)
char testWord3[] = "APPle";
printf("%s -> %s\n", testWord3
, isLegal
(testWord3
) ? "legal" : "illegal");
// Test word 4: "try" → legal (contains 'y')
char testWord4[] = "try";
printf("%s -> %s\n", testWord4
, isLegal
(testWord4
) ? "legal" : "illegal");
return 0; // indicate successful program end
}