Count Vowel Bookends
Difficulty: ⚫⚫◯◯
Tags: array, strings, counting
Hurdle: Passing this question is sufficient to pass the arrays hurdle.
Description
Write a function count_vowel_bookends that takes an array of strings with exactly size strings. Each string is terminated by the null terminator ('\0') character.
The function should return the count of strings that:
- Start with a vowel, AND
- End with a vowel
Vowels: a, e, i, o, u (and their uppercase versions A, E, I, O, U)
Important Rules:
- Both conditions must be met: The string must start AND end with a vowel to be counted.
- Case-insensitive: Both uppercase and lowercase vowels count.
- Empty strings (containing only
'\0') should NOT be counted. - Single character strings: A single vowel like
"a"or"I"counts (it both starts and ends with a vowel).
Examples
Example 1: Basic Cases
char *array[] = {
"apple", // starts 'a', ends 'e' -> YES
"banana", // starts 'b', ends 'a' -> NO (doesn't start with vowel)
"orange", // starts 'o', ends 'e' -> YES
"idea", // starts 'i', ends 'a' -> YES
};
// Result: 3
Example 2: Uppercase Works Too
char *array[] = {
"hello", // starts 'h' -> NO
"world", // starts 'w' -> NO
"APPLE", // starts 'A', ends 'E' -> YES
"Olive", // starts 'O', ends 'e' -> YES (mixed case)
};
// Result: 2
Example 3: Edge Cases
char *array[] = {
"a", // single vowel -> YES
"b", // single consonant -> NO
"I", // single uppercase vowel -> YES
};
// Result: 2
Example 4: All Match
char *array[] = {
"aardvarke", // a...e -> YES
"elite", // e...e -> YES
"origami", // o...i -> YES
};
// Result: 3
Example 5: None Match
char *array[] = {
"cat", // c...t -> NO
"dog", // d...g -> NO
"bird", // b...d -> NO
};
// Result: 0
Example 6: Starts with Vowel but Doesn't End with Vowel
char *array[] = {
"elephant", // e...t -> NO (ends with consonant)
"igloo", // i...o -> YES
"under", // u...r -> NO (ends with consonant)
};
// Result: 1
Function Signature
int count_vowel_bookends(int size, char *array[MAX_ROWS]);
Constants
#define MAX_ROWS 100
Constraints
- You can assume there will be at least one string (size >= 1).
- Each string will have at most 100 characters.
- Strings may be empty (contain only
'\0'). Empty strings should NOT be counted. - Both uppercase and lowercase vowels should be recognized.
- Do not modify the array provided.
- Do not call
scanf,getchar, orfgets. - Do not call
printf(the function should only return a value).
Hints
- Create a helper function to check if a character is a vowel.
- Use
strlen()to find the length of each string. - Remember to handle empty strings (length 0).
- The last character of a string is at index
length - 1.
Testing
./count-vowel-bookends apple banana orange idea
3
./count-vowel-bookends hello world APPLE Olive
2
./count-vowel-bookends a b I
2
./count-vowel-bookends cat dog bird
0