basics · beginner · ~15 min
Find the end of a string.
Return the final character of a string before its NUL terminator.
Implement char last_char(const char *s) that returns the last character of s (the one just before the terminating NUL), or '\0' if s is empty. No main — the grader calls it.
A NUL-terminated string s.
Returns the last character, or '\0' (0) when s is empty.
last_char("hello") -> 'o'
last_char("x") -> 'x'
last_char("") -> '\0'
'\0'.A NUL-terminated string s.
The last character, or '\0' if s is empty.
#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.