networking · beginner · ~15 min

Is this the last chunk?

Detect the terminating zero-chunk.

Challenge

Detect the terminating zero-sized chunk that ends a chunked HTTP body.

Task

Implement int is_last_chunk(const char *hexsize).

Input

  • hexsize: a chunk-size string in hexadecimal.

Output

Return 1 if the hex size parses to 0, else 0.

Example

is_last_chunk("0")    ->  1
is_last_chunk("000")  ->  1   (still zero)
is_last_chunk("10")   ->  0

Edge cases

  • Leading zeros ("000") still represent the terminating chunk.

Input format

hexsize: a chunk-size string in hexadecimal.

Output format

1 if the hex size parses to 0, else 0.

Constraints

Parse base-16 and compare to 0.

Starter code

#include <stdlib.h>

int is_last_chunk(const char *hexsize) {
    /* TODO */
    return 0;
}

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