Solutions to exercises from The C Programming Language (2nd Edition) by Brian W. Kernighan and Dennis M. Ritchie, commonly known as K&R.
You need a C compiler:
macOS:
xcode-select --installUbuntu / Debian:
sudo apt-get update && sudo apt-get install build-essentialWindows: Use WSL (recommended) or MinGW.
Build all exercises:
makeBuild a specific exercise:
cd chapter_1/exercise_1_01
make hello_world
./hello_worldClean up:
make cleanchapter_N/
exercise_N_XX/
solution.c # Solution source code
file_in.txt # Input file (if needed)
file_out.txt # Output file (if needed)
Contributions are welcome! See CONTRIBUTING.md for guidelines.
Quick start:
make format # Format your code
make check # Run all checks before submittingThe C Programming Language is a classic programming book. The exercises are designed so that you can solve them with the knowledge acquired up to that point in the book.
These solutions are meant to help those learning C. If you're working through the book, try solving the exercises yourself first!
- Editor: Any text editor works. VS Code with the C/C++ extension is recommended.
- Debugger: LLDB (macOS) or GDB (Linux)
- Formatter: clang-format
This project is open source. Feel free to use these solutions for learning!