networking · intermediate · ~15 min
Split an endpoint into host and numeric port.
Implement int parse_endpoint(const char *s, char *host, int hostsz, int *port) splitting "host:port" into its parts. Return 1 on success, 0 if there is no ':' or the port is invalid.
#include <string.h>
#include <stdlib.h>
int parse_endpoint(const char *s, char *host, int hostsz, int *port) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.