Learn C the Hard Way
A complete course in the C programming language for people who know at least one other language. If you are interested in languages like Rust, Go, Zig, JavaScript, C++, C#, Objective-C, and many, many more then learning C is a good first step. C is like the Latin of programming languages: Not something you should use every day, but learning unlocks so many other programming languages.
Course Contents
This course contains the following modules and lessons. Every course offers free samples of the first 10 lessons so you can decide if you want to take the course, and excerpts from all lessons after that.
Module Learn C the Hard Way
An introductory course in the C programming language.
- PrefaceThis is a rough in-progress dump of the book.
- This Book Is Not Really about CPlease don't feel cheated, but this book is not about teaching you C programming.
- Exercise 0: The SetupThe traditional first exercise, exercises 0, is where you setup your computer for the rest of this book.
- Exercise 1: Dust Off That CompilerNote: I mention a "PDF" in the video but that's not available anymore.
- Exercise 2: Using Makefiles to BuildWe're going to use a program called
make
to simplify building your exercise code. - Exercise 3: Formatted PrintingKeep that
Makefile
around since it'll help you spot errors, and we'll be adding to it when we need to automate more things. - Exercise 4: Using a DebuggerThis is a video-focused exercise where I show you how to use the debugger that comes with your computer to debug your programs, detect errors, and even debug processes that are currently running.
- Exercise 5: Memorizing C OperatorsWhen you learned your first programming language, it most likely involved going through a book, typing in code you didn't quite understand, and then trying to figure out how it worked.
- Exercise 6: Memorizing C SyntaxAfter learning the operators, it's time to memorize the keywords and basic syntax structures you'll be using.
- Exercise 7: Variables and TypesYou should be getting a grasp of how a simple C program is structured, so let's do the next simplest thing and make some variables of different types: ...
- Exercise 8: If, Else-If, ElseIn C, there really isn't a Boolean type.
- Exercise 9: While-Loop and Boolean ExpressionsThe first looping construct I'll show you is the
while-loop
, and it's the simplest, useful loop you could possibly use in C. - Exercise 10: Switch StatementsIn other languages like Ruby, you have a
switch-statement
that can take any expression. - Exercise 11: Arrays and StringsThis exercise shows you that C stores its strings simply as an array of bytes, terminated with the
'\0'
(nul) byte. - Exercise 12: Sizes and ArraysIn the last exercise, you did math but with a
'\0'
(nul) character. - Exercise 13: For-Loops and Arrays of StringsYou can make an array of various types with the idea that a string and an array of bytes are the same thing.
- Exercise 14: Writing and Using FunctionsUp until now, we've just used functions that are part of the `stdio.
- Exercise 15: Pointers, Dreaded PointersPointers are famous mystical creatures in C.
- Exercise 16: Structs And Pointers To ThemIn this exercise, you'll learn how to make a
struct
, point a pointer at it, and use it to make sense of internal memory structures. - Exercise 17: Heap and Stack Memory AllocationIn this exercise, you're going to make a big leap in difficulty and create an entire small program to manage a database.
- Exercise 18: Pointers to FunctionsFunctions in C are actually just pointers to a spot in the program where some code exists.
- Exercise 19: Zed's Awesome Debug MacrosThere's a reoccurring problem in C that we've been dancing around, but I'm going to solve it in this exercise using a set of macros I developed.
- Exercise 20: Advanced Debugging TechniquesI've already taught you about my awesome debug macros, and you've been using them.
- Exercise 21: Advanced Data Types and Flow ControlThis exercise will be a complete compendium of the available C data types and flow control structures you can use.
- Exercise 22: The Stack, Scope, and GlobalsThe concept of scope seems to confuse quite a few people when they first start programming.
- Exercise 23: Meet Duff's DeviceThis exercise is a brain teaser where I introduce you to one of the most famous hacks in C called Duff's device, named after Tom Duff the inventor.
- Exercise 24: Input, Output, FilesYou've been using
printf
to print things, and that's great and all, but you need more. - Exercise 25: Variable Argument FunctionsIn C, you can create your own versions of functions like
printf
andscanf
by creating a variable argument function or vararg funtion. - Exercise 26: Project logfindThis is a small project for you to attempt on your own.
- Exercise 27: Creative and Defensive ProgrammingYou have now learned most of the basics of C programming and are ready to start becoming a serious programmer.
- Exercise 28: Intermediate MakefilesIn the next three exercises you'll create a skeleton project directory to use in building your C programs later.
- Exercise 29: Libraries and LinkingA central part of any C program is the ability to link it to libraries that your OS provides.
- Exercise 30: Automated TestingAutomated testing is used frequently in other languages like Python and Ruby, but rarely used in C.
- Exercise 31: Common Undefined BehaviorAt this point in the book, it's time to introduce you to the most common kinds of UB that you will encounter.
- Exercise 32: Double Linked ListsThe purpose of this book is to teach you how your computer really works, and included in that is how various data structures and algorithms function.
- Exercise 33: Linked List AlgorithmsI'm going to cover two algorithms for a linked list that involve sorting.
- Exercise 34: Dynamic ArrayThis is an array that grows on its own, and have most of the same features as a linked list.
- Exercise 35: Sorting and SearchingIn this exercise, I'm going to cover four sorting algorithms and one search algorithm.
- Exercise 36: Safer StringsI already introduced you to the "Better String" Library in Exercise 26 when we made
devpkg
. - Exercise 37: HashmapsHash maps (hashmaps, hashes, or sometimes dictionaries) are used frequently in dynamic programming languages for storing key/value data.
- Exercise 38: Hashmap AlgorithmsThere are three hash functions that you'll implement in this exercise: FNV-1a: Named after the creators Glenn Fowler, Phong Vo, and Landon Curt Noll, this hash produces good numbers and is reasonably fast.
- Exercise 39: String AlgorithmsIn this exercise, I'm going to show you a supposedly faster string search algorithm, and compare it to the one that exists in `bstrlib.
- Exercise 40: Binary Search TreesThe binary tree is the simplest tree-based data structure, and even though it's been replaced by hash maps in many languages, it's still useful for many applications.
- Exercise 41: Project devpkgYou are now ready to tackle a new project called
devpkg
. - Exercise 42: Stacks and QueuesAt this point in the book, you should know most of the data structures that are used to build all of the other data structures.
- Exercise 43: A Simple Statistics EngineThis is a simple algorithm that I use for collecting summary statistics online, or without storing all of the samples.
- Exercise 44: Ring BufferRing buffers are incredibly useful when processing asynchronous I/O.
- Exercise 45: A Simple TCP/IP ClientI'm going to use the
RingBuffer
to create a very simplistic network testing tool callednetclient
. - Exercise 46: Ternary Search TreeThe final data structure that I'll show you is called the TSTree, which is similar to the
BSTree
, except it has three branches:low
,equal
, andhigh
. - Exercise 47: A Fast URL RouterI'm now going to show you how I use the
TSTree
to do fast URL routing in Web servers that I've written. - Exercise 48: A Simple Network ServerWe now start the part of the book where you do a long-running, more involved project in a series of exercises.
- Exercise 49: A Statistics ServerThe next phase of your project is to implement the very first feature of the
statserve
server. - Exercise 50: Routing the StatisticsOnce you've solved the problem of the protocol, and putting statistics into a data structure, you'll want to make this much richer.
- Exercise 51: Storing the StatisticsThe next problem to solve is how to store the statistics.
- Exercise 52: Hacking and Improving Your ServerThe final exercise consists of three videos.
- Next StepsThis book is most likely a monumental undertaking for a beginner programmer, or even a programmer with no experience with many of the topics covered inside.
- J.1 Unspecified behaviorThe manner and timing of static initialization (5.
- 1st Edition ErrataThe following errors were found after printing of the 1st edition of Learn C The Hard Way.