Learn › Learn C
C in Practice
C at work: strings and the standard library, file I/O, structs and the heap, debugging with gdb, tracing with strace, and signal handling. Ends with a CSV parser lab and the track capstone.
Labs in this module
- Strings and stdlib - A C string is a char array ending in a NUL terminator, and every string.h function trusts that stop mark. Measure the same char[6] two ways
- File I/O - Open, read, and close files from C with fopen, fgets, and fclose, and never trust an open you did not check. When fopen returns NULL, read e
- struct and the heap - Group related values into a struct, a shaped box with named fields, and give it a life longer than one function by renting memory on the hea
- Debugging with gdb - Compile with -g and drive a real gdb session on a real crash: run, backtrace, break, info locals, print, continue. Read a SIGSEGV backtrace
- Tracing with strace - The syscalls behind printf and fopen. Put strace on a working file reader and watch fopen become openat, the fgetc loop become one buffered
- Signals - Signals are the kernel's asynchronous messages to a process: SIGINT from Ctrl-C, SIGTERM from kill, SIGKILL from kill -9. Watch the default
- Lab: CSV Parser - A CSV parser using struct and malloc, freed clean under valgrind.
- Learn C Capstone - Write a 4-function C utility from scratch to a spec, graded by compiler warnings, an input matrix, and valgrind.