Skip to main content

Practice ยท 1 of 1

The Fixed-Width Record Store

Implement a tiny record store over /tmp/cj_records.bin. The boilerplate declares: ``c /* file format: bytes 0..3 : magic "CJR1" bytes 4..5 : uint16 record count (little-endian) then records of exactly 8 bytes each: byte 0 : id (0..255) bytes 1..4: int32 qty little-endian bytes 5..7: zero padding */ int rs_create(const char *path); /* fresh empty store */ int rs_append(const char *path, unsigned id, int qty); /* 0 ok, -1 err/bad args */ int rs_read(const char *path, size_t index, unsigned *id, int *qty); /* 0 ok, -1 out of range/err */ size_t rs_count(const char *path); /* 0 if absent/invalid */ `` All multi-byte fields little-endian, byte by byte (endianness tax).

Difficulty: intermediate

Back to lesson: Practice: Record I/O Gym