pointers-memory · intermediate · ~15 min
Nested pointer iteration; corner cases of empty inputs.
Implement const char *my_strstr(const char *haystack, const char *needle) that returns a pointer to the first occurrence of needle in haystack, or NULL if not found. An empty needle returns haystack.
#include <stddef.h>
const char *my_strstr(const char *haystack, const char *needle) {
/* TODO */
return NULL;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.