basics · beginner · ~15 min

First character

Index into a char array and handle the empty case.

Challenge

Implement char first_char(const char *s) returning the first character, or '\0' if the string is empty.

Starter code

char first_char(const char *s) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.