networking · intermediate · ~15 min

Parse a chunk size

Convert a hex chunk-size line to a number.

Challenge

In HTTP chunked encoding each chunk starts with its size in hex. Implement long parse_chunk_size(const char *hex) returning the value of the hex string, or -1 if it has no hex digits.

Starter code

#include <stdlib.h>
#include <ctype.h>

long parse_chunk_size(const char *hex) {
    /* TODO */
    return -1;
}

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