Skip to content

📘 My solutions to the exercises in the book "The C Programming Language" (2nd edition) by Brian W. Kernighan and Dennis M. Ritchie.

License

Notifications You must be signed in to change notification settings

albrechtcolia/the-c-programming-language-solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation


These are my solutions to exercises from the classic "The C Programming Language" by Brian Kernighan and Dennis Ritchie (2nd edition), also referred to as "K&R". The exercises in the book are very didactic and fun, I hope you enjoy them. :)

I found some descriptions and examples of the exercises on this site: www.learntosolveit.com.

Project under development.


📑 Table of Contents



📚 Summary

Chapter 01

  • 01 - Hello World
  • 02 - Escape sequences
  • 03 - Fahrenheit-Celsius conversion table (0 to 300)
  • 04 - Celsius-Fahrenheit conversion table
  • 05 - Fahrenheit-Celsius conversion table (300 to 0)
  • 06 - Verifying the expression value
  • 07 - Verifying EOF value
  • 08 - Blank space counter
  • 09 - Blank replacement
  • 10 - Escape sequence replacement
  • 11 - Word counter
  • 12 - String splitter
  • 13 - Word length histogram
  • 14 - Character frequency histogram
  • 15 - Fahrenheit-Celsius conversion table (using functions)
  • 16 - Longest line program (character limit)
  • 17 - Print longer than 80 characters
  • 18 - Remove trailing blanks and tabs
  • 19 - Reverses the string
  • 20 - Replaces tabs in the input with the proper number of blanks
  • 21 - Replaces strings of blanks with the minimum number of tabs and blanks
  • 22 - Splits a long string into short strings
  • 23 - Removes all comments from a C program
  • 24 - Checks for rudimentary syntax errors

Chapter 02

  • 01 - Type ranges
  • 02 - Loop that represents '&&' or '||' in another way
  • 03 - Hexadecimal to decimal converter
  • 04 - Alternate version of squeeze function
  • 05 - Occurrence finder
  • 06 - Setting bits at a position n
  • 07 - Setting bits at a position n inverted
  • 08 - Funciton that returns the value of the integer rotated to the right
  • 09 - Two's complement number system
  • 10 - Upper case to lower case

Chapter 03

  • 01 - Binsearch function
  • 02 - Escape sequences into the real characters
  • 03 - Expand short hand notation into string
  • 04 - Itoa to handle largest negative integer
  • 05 - Converts an integer into a string
  • 06 - Itoa with field width

Chapter 04

  • 01 - Find the pattern in the line and print it
  • 01 - Strindex which returns rightmost occurance
  • 02 - Atof - converts string to double
  • 02 - Extend atof to handle scientific notation
  • 03 - Reverse Polish Notation calculator
  • 03 - RPN modulus operator and negative numbers
  • 04 - RPN Calculator - print two top elements of the stack without popping
  • 05 - RPN calculator with mathematical functions
  • 06 - RPN calculator with variables
  • 07 - Function ungets that will push back an entire string onto the input
  • 08 - Getch and ungetch handling pushback character
  • 09 - Getch and ungetch handling EOF character
  • 10 - Calculator using getline
  • 11 - Getline using static
  • 12 - Convert integer into string by calling recursive routine
  • 13 - String reverse function
  • 14 - Swap that interchanges two arguments of type t

Chapter 05

  • 01 - Get next integer from input
  • 02 - Get next float from input
  • 03 - Concatenates two strings
  • 04 - Checks if a string occurs at the end of another string
  • 05 - Simple versions of strncpy, strncat, and strncmp
  • 06 - Find the pattern using pointers
  • 06 - Pointer to arrays
  • 07 - Readlines using array
  • 08 - Date Duration Calculator
  • 09 - Date Duration Calculator using pointers
  • 10 - Evaluates a reverse polish expression from the command line
  • 11 - Entab and detab which accepts arguments
  • 12 - Extended entab and detab
  • 13 - Prints the last n lines of its input
  • 14 - Sorting in reverse order
  • 15 - Fold upper and lower case together
  • 16 - Compares only letters, numbers and blanks
  • 17 - Sorting with options
  • 18 - Recover from input errors
  • 19 - Undcl that does not add redundant parentheses
  • 20 - Expanded dcl to handle declarations with function argument types, qualifiers, and so on

Chapter 06

  • 01 - Getword
  • 02 - Identical variables
  • 03 - Arrays of structures
  • 03 - Cross referencer
  • 04 - Words and frequency
  • 05 - Undef - remove name and definition from table
  • 06 - Simple version of the #define processor

Chapter 07

  • 01 - Upper case to lower and lower case to upper
  • 02 - Prints non-graphical characters in octal or hexadecimal
  • 03 - Minimalistic printf function
  • 04 - Minimalistic scanf function
  • 05 - Postfix calculator using scanf
  • 06 - Compare two files
  • 07 - Pattern matching program with files
  • 08 - Print pages to files
  • 09 - Analyze implementations of isupper

Chapter 08

  • 01 - Program cat using Read, Write, Open and Close
  • 02 - Read and Write
  • 02 - Buffered and Unbuffered getchar
  • 02 - Fopen and _fillbuf with fields instead of explicit bit operations
  • 03 - Open and create calls
  • 03 - Fflush, _flushbuf and fclose
  • 04 - Implementation of fseek
  • 05 - Inode entry
  • 06 - Alternate version of calloc function
  • 07 - Error checking by malloc
  • 08 - Bfree maintained by malloc

😃 Author

Twitter: Albrechtcolia


📜 License

BSD-3-Clause license

About

📘 My solutions to the exercises in the book "The C Programming Language" (2nd edition) by Brian W. Kernighan and Dennis M. Ritchie.

Topics

Resources

License

Stars

Watchers

Forks

Languages