Return the number of English vowels in a null-terminated string. Count upper- and lower-case letters, and treat a null pointer as an empty string.
Requirements
Stop at '\0'
Count a, e, i, o, u in both cases
Never modify the input
Example
Input
SovranCode
Expected output
4
Show a hint
Write down the input contract and the failure cases before coding.
local runtime
RUNTIME OUTPUT
Use your C runtime locally, then compare with solution.c.
Use your local runtime, then review the reference solution
LEARN FROM THE SOLUTION
Why the solution works.
A C string has no length stored beside it; its contract is the terminating null character. A read-only cursor makes that contract visible and keeps the caller's buffer unchanged. The switch handles both cases without locale-dependent surprises.
What this exercise teaches
C string traversal
Character comparisons
Null termination
A PRACTICAL PLAN
Work through Count vowels in a C string with intent.
Translate the contract.Turn the requirements into a short checklist before editing your-solution.c.
Use the example as evidence.Predict the result for the supplied input, then add one boundary case such as an empty value, a limit, or unexpected input.
Review the implementation.Compare your choices against solution.c only after a real attempt.
EXERCISE FAQ
Before you move on.
What does “Count vowels in a C string” teach?
This beginner C exercise focuses on C string traversal, Character comparisons, Null termination. Its requirements define the exact behavior to implement before you write code.
How should I validate this C solution?
Start with the displayed example input and expected output, then test a boundary case suggested by the requirements. Write and compile the starter in your local C environment, exercise the example and edge cases, then compare your approach with solution.c.
When should I open the reference solution?
Attempt Count vowels in a C string first. Then open the read-only solution file to compare the contract, edge-case handling, and implementation choices—not simply to copy the final code.