networking · beginner · ~15 min

Build a host:port string

Format a connection endpoint string.

Challenge

Implement int build_endpoint(char *out, int outsz, const char *host, int port) writing "host:port" into out and returning its length (use snprintf).

Starter code

#include <stdio.h>

int build_endpoint(char *out, int outsz, const char *host, int port) {
    /* TODO */
    return 0;
}

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