networking · beginner · ~15 min

Parse a port number string

Strict integer parsing with a domain check.

Challenge

Implement int parse_port(const char *s) returning the port number (1..65535) or -1 on bad input (non-digit chars, out of range).

Starter code

int parse_port(const char *s) { /* TODO */ return -1; }

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.