Strings In Depth3 / 18
Up next

Walk char by char

#include <stdio.h>

int main(void) {
    const char *s = "education";
    int vowels = 0;
    for (const char *p = s; *p != '\0'; p++) {
        switch (*p) {
            case 'a': case 'e': case 'i': case 'o': case 'u':
                vowels++;
                break;
        }
    }
    printf("%d vowels\n", vowels);
    return 0;
}
What you're solving

a NUL byte marks the end