C practice
You reinforce loop, pointer, memory and file skills in C with short, realistic problems and test every solution against an automatic checker.
Level 201 · 19 lessons · 18 practice labs
Lessons
Warm-up
- Exercise: condition and loop puzzles
- Exercise: binary, octal and hex conversion
- Exercise: bit masks and flags
- Exercise: max, min and duplicates in an array
- Exercise: reversing strings and palindromes
- Short task: a mixed warm-up set
Pointers and memory
- Exercise: swapping with pointers and rotating arrays
- Exercise: dynamic matrix multiplication
- Exercise: your own split function
- Exercise: find and fix the leak
- Exercise: fix the off-by-one bugs
- Short task: until Valgrind reports clean
Files and tools
- Exercise: a wc-like counter
- Exercise: a tiny grep
- Exercise: a sort and uniq style tool
- Exercise: a CRC32 checksum
- Exercise: Caesar and XOR encoding, and why it is not encryption
- Short task: deliver a command-line tool with its tests
Capstone
- Capstone: five problems that pass the automatic checker
Practice labs
- Converting Roman numerals to numbers: Write a function that converts a Roman numeral string to an integer, returning -1 for invalid letters.
- Encoding and decoding Gray code: Write functions that convert a number to Gray code and back using bit operations.
- Turning an IPv4 address into a number: Write functions that turn a dotted IPv4 address into a 32-bit number and back, rejecting errors like 256 or missing dots.
- Rotating an array by k steps: Write a function that rotates an array right by k steps without extra memory, where k may exceed the length.
- Compressing repeated characters: Write a compression function that turns "aaabcc" into "a3b1c2" without overrunning the output buffer.
- Grouping anagram words: Group the anagrams in a word list and print each group on one line, ignoring case.
- Transposing a dynamic matrix: Produce the transpose of a malloc'd rows x cols matrix in a new matrix and free both.
- Freeing a split string array without leaks: Write a helper that frees the char** array returned by a split function and prove with Valgrind it is clean.
- Hunting a hidden off-by-one bug: Find and fix the off-by-one in a copy loop whose tests crash now and then, using ASan.
- Preventing use after free in a queue: Find the bug where a job queue touches a node after it was freed, fix it and get a clean Valgrind report.
- A small head-like tool: Write a tool that prints the first N lines of a file, supporting the -n option and stdin.
- A cut-like field selector: Write a tool that takes a delimiter and field number and prints that field from each line, leaving short lines empty.
- A tr-like character translator: Write a tr-like tool that maps or deletes characters, supporting ranges like a-z, and pass the tests.
- The Adler-32 checksum: Implement the Adler-32 checksum and pass the tests that compare it with known sample values.
- Writing a Base64 encoder: Write a Base64 encoder that converts random byte arrays correctly, including the padding characters.
- A strict Base64 decoder: Write a Base64 decoder that errors on invalid characters, bad padding or wrong length and never overruns its buffer.
- Finding an uninitialised total variable: Find the uninitialised variable in an invoice totaller that is sometimes right and sometimes garbage, fix it and show a clean Valgrind run.
- Catching an overlapping memory copy: Find the copy that corrupts overlapping regions in a text editor core that shifts data within a buffer and repair it so the random shift tests pass.
About this course
You reinforce loop, pointer, memory and file skills in C with short, realistic problems and test every solution against an automatic checker.
What you will learn
- Warm-up
- Pointers and memory
- Files and tools
- Capstone
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.