C Study Plan — From Fundamentals to a Disk-Based KV Store
Roughly 6 weeks (40 days), assuming ~1–2 hours/day. Adjust pace as needed — better to go slow and actually type/run every example than to rush.
Each day: read/learn the topic, then write a small program that uses it. Don’t just read — compile and run everything.
Week 1 — Core Syntax
- Day 1 —
#include,printf,main, compiling withgcc, comments - Day 2 — Variables, data types (
int,float,double,char),sizeof - Day 3 — Operators (arithmetic, relational, logical), operator precedence
- Day 4 —
if/else,switch - Day 5 —
for,while,do...whileloops - Day 6 — Functions: declaration, definition, return values, parameters
- Day 7 — Review day: write 3–4 small programs combining Days 1–6 (e.g. a calculator, a number-guessing game)
Week 2 — Pointers and Arrays
- Day 8 — Arrays: declaration, indexing, iterating
- Day 9 — Pointers:
&,*, pointer arithmetic basics - Day 10 — Pointers and arrays: how arrays decay to pointers
- Day 11 — Strings as char arrays:
strlen,strcpy,strcmp,<string.h> - Day 12 — Multi-dimensional arrays; pointers to pointers (
char**) - Day 13 —
constcorrectness with pointers; passing arrays/pointers to functions - Day 14 — Review day: write a program that tokenizes a sentence into words manually
Week 3 — Memory and Structs
- Day 15 — Stack vs. heap;
malloc,free,calloc,realloc - Day 16 — Common memory bugs: leaks, dangling pointers, double-free (use
valgrindif available) - Day 17 —
structbasics: declaration, member access,->vs. - Day 18 — Structs containing pointers;
typedef - Day 19 — Dynamically allocated structs; arrays of structs
- Day 20 — Building a simple linked list (insert, traverse, free)
- Day 21 — Review day: implement a dynamic array (“vector”) that grows with
realloc
Week 4 — Files, Errors, and Bigger Data Structures
- Day 22 — File I/O:
fopen,fread,fwrite,fclose,fseek, text vs. binary mode - Day 23 — Error handling patterns in C: return codes,
errno,perror - Day 24 — Function pointers; using them as callbacks/comparators
- Day 25 —
enumandunion; designing tagged unions for variant types - Day 26 — Hash tables: theory (buckets, collisions, load factor)
- Day 27 — Implement a basic hash table (insert/lookup/delete) from scratch
- Day 28 — Binary trees: theory and a simple in-memory BST (insert/search)
Week 5 — Systems-Level Concepts (prep for the capstone)
- Day 29 — Bitwise operators, bit flags, why they matter for binary formats
- Day 30 — Designing binary file formats: struct packing, alignment, padding
- Day 31 — Fixed-size records and “pages”: simulating disk pages in memory
- Day 32 — B-trees: theory — why databases use B-trees instead of BSTs
- Day 33 — Command-line arguments (
argc/argv), building a simple CLI tool - Day 34 —
Makefilebasics: targets, dependencies, compiling multi-file projects - Day 35 — Review day: write a program that serializes/deserializes a struct to a binary file and reads it back correctly
Week 6 — Capstone: The Disk-Based KV Store
Build incrementally, testing each layer before moving to the next.
- Day 36 — Set up project structure (
include/,src/,tests/,Makefile). Implement the pager:pager_open,pager_get_page, fixedPAGE_SIZEreads/writes to a file - Day 37 — Add the page cache to the pager (in-memory array of loaded pages, dirty tracking,
pager_flush) - Day 38 — Implement a single-page B-tree: insert and search only, no splitting yet (tree fits in one page)
- Day 39 — Implement node splitting so the B-tree can span multiple pages — this is the hardest part, budget extra time
- Day 40 — Implement
btree_deletewith basic merging; wire everything into the publickv_get/kv_put/kv_deleteAPI and a CLI inmain.c
Optional Day 41+ (stretch goals, once the core works)
- Add the write-ahead log (
wal.c) for crash safety - Add a simple range scan (iterate keys in sorted order)
- Add basic concurrency: a single global mutex around reads/writes using
pthread
Tips for sticking with it
- Compile with
-Wall -Wextrafrom Day 1 — let the compiler catch mistakes early. - Use
valgrind(or ASan:gcc -fsanitize=address) starting Week 3 onward. It will save you hours of confusion. - If a day’s topic feels shaky, repeat it before moving on — Weeks 5–6 depend heavily on Weeks 2–3 being solid.
- When you reach Day 36, come back and we can go through the pager/B-tree code together step by step.