Master the fundamental concepts of c programming deep dive through this focused micro-challenge.
Variadic functions in C rely on stdarg.h. The caller places extra arguments according to the ABI; va_start, va_arg, and va_end let the callee walk them. Every printf, syslog, and kernel printk uses this machinery. GCC's -Wformat exists because a %s with an int argument is UB and a classic CVE category.
cLoading…
int, print digits (handle negatives)char*, print until \0; print (null) if the pointer is NULLunsigned, print hex nibblesva_argWalk the format string character by character. Ordinary characters go to putchar; a percent starts specifier handling.
For this exercise, you will implement my_printf with those four specifiers and return a character count. This task asks you to see format strings as a protocol between caller and callee, because mismatched specifiers break security checks and logging pipelines in real systems.
Keep the relevant man page, ABI doc, or Rust reference chapter open while you work. When your output disagrees with the reference implementation on the same machine, the mismatch is usually an alignment rule, an off-by-one terminator, or a register slot you misread in GDB.
Implement a simplified version of printf from scratch.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github