C strings and null terminators

A C string ends with a zero-valued character, written '\0'. A string literal used to initialize a char array supplies that terminator automatically.

C
#include <stdio.h>
#include <assert.h>
int main(void) {
    const char text[] = "learning";
    int count = 0;
    for (int i = 0; text[i] != '\0'; i++) {
        if (text[i] == 'a' || text[i] == 'e' || text[i] == 'i') {
            count++;
        }
    }
    printf("%d\n", count);
    assert(count == 3);
    return 0;
}
Read the full lesson