{"id":15049483,"url":"https://github.com/jsgoller1/c-programming-language","last_synced_at":"2026-03-11T09:32:36.985Z","repository":{"id":106179561,"uuid":"120970576","full_name":"jsgoller1/c-programming-language","owner":"jsgoller1","description":"Solutions to every exercise from \"The C Programming Language\" by Kernighan / Ritchie (K\u0026R)","archived":false,"fork":false,"pushed_at":"2020-11-21T18:33:22.000Z","size":746,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T02:17:06.571Z","etag":null,"topics":["c","cs-books","k-and-r"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsgoller1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-10T00:34:18.000Z","updated_at":"2024-02-27T15:26:39.000Z","dependencies_parsed_at":"2023-06-16T00:30:12.927Z","dependency_job_id":null,"html_url":"https://github.com/jsgoller1/c-programming-language","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jsgoller1/c-programming-language","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsgoller1%2Fc-programming-language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsgoller1%2Fc-programming-language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsgoller1%2Fc-programming-language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsgoller1%2Fc-programming-language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsgoller1","download_url":"https://codeload.github.com/jsgoller1/c-programming-language/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsgoller1%2Fc-programming-language/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30377279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cs-books","k-and-r"],"created_at":"2024-09-24T21:20:40.853Z","updated_at":"2026-03-11T09:32:36.964Z","avatar_url":"https://github.com/jsgoller1.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The C Programming Language (K\u0026R)\nSolutions for every exercise from \"The C Programming Language\" by Kernighan / Ritchie. \n\n## Goals\n This was the first \"classic CS book\" that I read; in addition to learning C, I also learned how to write code productively and how to read a CS textbook. As such, my goals for this textbook changed as I read it (especially given that I jumped around a good bit). I settled on the following definition for \"complete\":\n- All pages read, including the appendices\n- All exercises solved, with maximum const correctness\n- All solutions compile against C11 with `-Werror -Wall`\n- All solutions report no issues from Clang's static analyzer (`scan-build`), excluding false positives\n- All solutions report no memory leaks in `valgrind` when run with `--leak-check=full --show-leak-kinds=all`\n\nI have _not_ tried to hold to the text as closely as possible at the cost of writing straightforward code; e.g. I may use structs in my solutions in chapter 5 despite them not being introduced til chapter 6.\n\n## Running via Makefile\nAll exercises are built via Makefile and should be executed from the top-level of the repo, inside the Dockerized workspace (see `makefiles/docker.mk` for targets to create this workspace).\n\nEvery exercise either has its own target (e.g. `make 5.4` will make exercise 4 in chapter 5) or is grouped into a subproject with its own target (e.g. 5.14 - 5.17 are all about the `sort` program, so they exist in `ch-5/sort/` and are built with `make sort`). Chapters also have their own targets (e.g. all exercises from chapter 6 are buildable with `make ch-6`), and `make all` builds everything. All buildable targets are listed in the top-level Makefile, at the botom.\n\nThe Makefile system is divided into four parts:\n* Chapter-specific Makefiles containing specific patterns for building and testing individual exercises.\n* A `docker.mk` for managing the Dockerized workspace.\n* A `buikding.mk` containing build settings; you can find targets for producing binaries and toggle valgrind, static analysis, and tests from this file.\n* A top level Makefile tying everything together; all exercises should be built in the top-level directory of the repo.\n\n## Top Highlights\n* `ch-8/malloc_j/` - a storage allocator / the final boss of K\u0026R\n* `common/trees/` - a generic binary search tree library I wrote to handle exercises in Chapter 6\n* `ch-8/fopen_j/` - buffered FILE I/O\n* `common/tests/` - a simple unit testing library that wraps around the `assert(3)` macro; I wound up not using this too much beyond ch-1 as my testing stategy evolved.\n* `faq/` - Experiments / questions I had to test my understanding of C as I read K\u0026R.\n\n## Conventions\nI have my editor set up to run `clang-format -i --style=Google` on save.\n\n## Notes about the exercises\n* Each chapter / subproject has its own README.md; see these for specific notes.\n* For programs reading from stdin, it is expected behavior that you will need to hit CTRL-D twice to exit if the last character entered was not a newline - this behavior is defined by the POSIX standard (see this [Stack Overflow question](https://stackoverflow.com/questions/21260674/why-do-i-need-to-type-ctrl-d-twice-to-mark-end-of-file?utm_medium=organic\u0026utm_source=google_rich_qa\u0026utm_campaign=google_rich_qa)).\n\n## Source text\nYou can find the full 2nd edition text with examples [here](http://cs.indstate.edu/~cbasavaraj/cs559/the_c_programming_language_2.pdf). You can find problem statements and solutions [here](https://clc-wiki.net/wiki/K%26R2_solutions:Chapter_4).\n\n## Special thanks\n* [Elliott Jin](https://github.com/robot-dreams) for the many hours of help with debugging and review.\n* [Steven Harris](https://github.com/seh) for feedback on the RPN calculator.\n* [Michael McLoughlin](https://github.com/mmcloughlin) for help on buffered FILE I/O.\n* [Bartosz Wróblewski](https://github.com/bawr) for feedback on the memory allocator.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsgoller1%2Fc-programming-language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsgoller1%2Fc-programming-language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsgoller1%2Fc-programming-language/lists"}