networking · beginner · ~15 min
Recognise local-only test targets.
Recognise the spellings that all refer to the local machine.
Implement int is_localhost(const char *host).
host: a NUL-terminated host string.Return 1 if host is exactly "localhost", "127.0.0.1", or "::1"; else 0.
is_localhost("localhost") -> 1
is_localhost("127.0.0.1") -> 1
is_localhost("::1") -> 1
is_localhost("example.com") -> 0
host: a NUL-terminated host string.
1 if host is "localhost", "127.0.0.1", or "::1"; else 0.
Exact match against the three loopback spellings.
#include <string.h>
int is_localhost(const char *host) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.