linux-sysprog · intermediate · ~15 min
Format bytes safely with snprintf into a bounded buffer.
Implement int hexdump_line(const unsigned char *data, size_t n, char *out, size_t out_sz) that writes xx xx xx ... |ascii| representation of up to 16 bytes. Returns 0 on success or -1 if the buffer is too small.
#include <stdio.h>
#include <ctype.h>
#include <stddef.h>
int hexdump_line(const unsigned char *data, size_t n, char *out, size_t out_sz) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.