basics · beginner · ~15 min
Combine the two-pointer pattern with C strings.
Reverse a C string in place, character by character.
Implement void reverse(char *s) that reverses the NUL-terminated string s in place. No main — the grader calls it.
A writable, NUL-terminated string s (may be empty).
Nothing is returned. The characters of s are reversed; the string stays NUL-terminated.
"hello" -> "olleh"
"ab" -> "ba"
"racecar" -> "racecar"
length - 1 does not underflow for size_t.A writable NUL-terminated string s.
Nothing returned; s is reversed in place.
In place, no new allocation; handle the empty string safely.
#include <string.h>
void reverse(char *s) {
/* TODO */
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.