This repo contains solutions for the exercises of each chapter in the K&R book. The aim is to open source my solutions as a helpful reference for future readers.
The C Programming Language written by Brian Kernighan and Dennis Ritchie is an invaluable resource for learning the core concepts of programming in C. It is often referred to as the K&R book.
Each chapter of the book contains exercises related to the discussed content.
- Chapter 1: A Tutorial Introduction
- Chapter 2: Types, Operators and Expressions
- Chapter 3: Control Flow
- Chapter 4: Functions and Program Structure
- Chapter 5: Pointers and Arrays
- Chapter 6: Structures
- Chapter 7: Input and Output
- Chapter 8: The UNIX System Interface
The provided solutions are independent of any IDE. You can run the solutions individually using a C compiler of your choice.
If you are using VS Code, you can use the tasks.json and launch.json to easily compile and execute each file. I also recommend using the C/C++ extension by Microsoft for IntelliSense, debugging and code browsing. To show the debug button in VS Code for each C file, you can enable the C_Cpp: Debug Shortcut under Settings > Extensions > C/C++.
For some of the exercises, you will be able to run tests with Ceedling. The tests are provided in the tests
directory.
Once you have Ceedling installed, you can run them using the ceedling
command.
ceedling test:all # run all the tests
ceedling test:name # test specific test suite with `name`
If you find any mistake or can think of a more optimized or cleaner solution, please let me know! I'd be happy to hear from you.