C language fundamentals
You learn C, the language of operating systems and many security tools, from scratch, including working with the compiler and reading its warnings.
Level 101 · 21 lessons · 21 practice labs
Lessons
Getting started
- A first program with gcc: compile and run: You compile a C source file with gcc, run it and learn what the return value of main means.
- Compilation stages: preprocessor, compiler, linker: You follow the steps that turn source code into an executable by inspecting gcc’s intermediate outputs.
- Variables, types and sizeof: You know int, char, float and double and measure the memory each takes with sizeof.
- Operators and bitwise operations: You use arithmetic and logical operators along with bit operations such as AND, OR, XOR and shifts.
- Input and output with printf and scanf: You produce output with format specifiers and see why input reading needs limits.
- Short task: a unit converter
Control flow and functions
- Conditions: if, else and switch: You write decisions and know that in C zero counts as false and everything else as true.
- Loops: for, while, do-while: You write repeated work with the right loop and avoid off-by-one mistakes.
- Functions: parameters, returns and prototypes: You split code into functions, declare them with prototypes and see that values are passed by copy.
- Scope and storage classes: local, global, static: You decide where a variable lives and how long it stays by using static and extern.
- Arrays and multi-dimensional arrays: You define and traverse arrays and understand that C does not check bounds, so overruns corrupt data silently.
- C strings: char arrays and the terminator: You learn that text ends with a \0 byte, how string.h functions rely on it and which mistakes follow.
- Short task: a grade report
Structures, files and errors
- struct, enum and typedef: You group related data with struct, name fixed choices with enum and improve readability with typedef.
- Header files and multi-file projects: You split code into .c and .h files, use include guards, and compile and link files separately.
- Build automation with make and Makefiles: You define targets and dependencies in a Makefile and rebuild only the files that changed.
- Compiler warnings: -Wall, -Wextra and -Werror: You turn on warning flags, treat warnings as errors and catch common defects at compile time.
- File I/O: fopen, fgets, fprintf, fclose: You open text files, read and write them line by line and close every file you open.
- Error checking: return values and errno: You check the return values of system and library calls and give meaningful messages with perror.
- Short task: a contact list saved to a file
Capstone
- Capstone: a C program that counts events in a log file: You combine what you learned into a multi-file program that reads a log line by line and counts events.
Practice labs
- Printing an aligned price list: Print product names and prices in aligned columns with printf width and precision specifiers and pass the output test.
- Checking the return value of scanf: Fix age-reading code that loops forever when a letter is typed by checking scanf's return value and clearing the input.
- Hardening a fuel cost calculator: Make a calculator that reads distance and consumption give meaningful errors for negative, zero and huge inputs.
- Reading permission bits with masks: Extract the read, write and execute bits from a permission value with & and print them in rwx form.
- Packing colour components into one number: Write two functions that pack red, green and blue values into a 32-bit number with shifts and unpack them again.
- Managing flags in a device register: Write functions that set, clear and toggle given bits in a device register and test that other bits stay untouched.
- Finding the number of days in a month: Write a switch-based function that takes a year and month and returns the number of days, including leap years.
- Calculating a tiered parking fee: Write a function that applies tiered hourly rates and a daily cap for the Mavikoy Municipality car park.
- Gathering hidden global state with static: Rewrite an id generator tangled in global variables using a static local and file scope without breaking the tests.
- Statistics for a weekly temperature array: Write a function that computes the minimum, maximum and average of a seven-day temperature array.
- Counting characters up to the terminator: Write a function that walks a char array up to \0 without strlen and counts vowels and consonants.
- Finding adjacent seats in a cinema: Write a function that finds the requested number of free adjacent seats in a 2D seat array without going out of bounds.
- Keeping a book record in a struct: Define a struct holding title, author and year for Çınaraltı Library and add a function that prints the record on one line.
- Managing order states with an enum: Define an enum for order states and write a function that accepts only the allowed transitions.
- Sorting a staff array by two fields: Write a sort that orders a struct array by department and then by name, keeping equal records in their original order.
- Reporting a file open error with errno: Add an fopen check to code that opens a settings file and print a clear message with strerror(errno) on failure.
- Writing a Makefile for a two-file project: Write a Makefile for a project of one header and two .c files that rebuilds only what changed.
- Clearing -Wall -Wextra warnings: Make a small program full of warnings build with -Wall -Wextra -Werror, fixing the two real bugs hidden among them.
- Compiling and linking two files by hand: Compile two source files separately with gcc -c, link the object files and remove the warning caused by a missing prototype using a header file.
- Counting lines in a file with fgets: Read a text file line by line with fgets and count the non-empty lines, getting the count right even when the last line has no newline, and close the file.
- Copying a file with every step checked: In a program that copies a file with fread and fwrite, check read, write and close errors separately; on error delete the half-written target and exit with a non-zero code.
About this course
You learn C, the language of operating systems and many security tools, from scratch, including working with the compiler and reading its warnings.
What you will learn
- Getting started
- Control flow and functions
- Structures, files and errors
- Capstone
Prerequisites
No prior knowledge is needed; the course starts from zero.
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 beginner level; every term is explained where it first appears.
- 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.