basics · beginner · ~15 min

Last character

Find the end of a string.

Challenge

Implement char last_char(const char *s) returning the last character before the NUL, or '\0' if empty.

Starter code

#include <string.h>

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

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