Giter VIP home page Giter VIP logo

tcpl's Introduction

The C Programming Language

Collection of examples and exercises from The C Programming Language, 2nd Ed., by Brian W. Kernighan and Dennis M. Ritchie

Examples

Note: Examples from the book are not numbered. The numbering provided here is made up.

Chapter 1
Number Page Description
1-1 7 Simple "Hello World" program.
1-2 9 Print sample Fahrenheit-Celsius table using integers only.
1-3 12 Print sample Fahrenheit-Celsius table using floating-points numbers.
1-4 13 Print sample Fahrenheit-Celsius table using floating-points numbers and for loop.
1-5 15 Print sample Fahrenheit-Celsius table using floating-points numbers, for loop and constants.
1-6 16 Copy input to output, one character at a time (1st version).
1-7 17 Copy input to output, one character at a time (2nd version).
1-8 18 Count characters in input (1st version).
1-9 18 Count characters in input (2nd version).
1-10 19 Count lines in input.
1-11 20 Count words in input. This is a bare-bones version of the UNIX program wc.
1-12 22 Count digits, white space, others.
1-13 24 Function power to compute the power of a number.
1-14 27 Function power to compute the power of a number, using "call by value".
1-15 29 Print longest line from input.
1-16 29 Print longest line from input, using external variables.

Exercises

Chapter 1
Number Page Prompt
1-3 13 Modify the temperature conversion program to print a heading above the table.
1-4 13 Write a program to print the corresponding Celsius to Fahrenheit table.
1-5 14 Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0.
1-6 17 Verify the expression getchar() != EOF is 0 or 1.
1-7 17 Write a program to print the value of EOF.
1-8 20 Write a program to count blanks, tabs, and newlines.
1-9 20 Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.
1-10 20 Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspaces visible in an unambiguous way.
1-11 21 How would you test the word count program? What kinds of input are most likely to uncover bugs if they are any?
1-12 21 Write a program that prints its input one word per line.
1-13 24 Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging.
1-14 24 Write a program to print a histogram of the frequencies of different characters in its input.
1-15 27 Rewrite the temperature conversion program (example 1-5) to use a function for conversion.
1-16 30 Revise the main routing of the longest-line program (example 1-15) so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text.
1-17 31 Write a program to print all input lines that are longer than 80 characters.
1-18 30 Write a program to remove trailing blanks and tabs from each line of input, and to delete entirely blank lines.
1-19 30 Write a function reverse(s) that reverses the character string s. Use it to write a program that reverses its input a line at a time.
1-20 34 Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter?
1-21 34 Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab. When either a tab of a single blank would suffice to reach a tab stop, which should be given preference?
1-22 34 Write a program to "fold" long input lines into two or more shorter lines after the last non-blank character that occurs before the n-th column of input. Make sure your program does something intelligent with very long lines, and if there are no blanks or tabs before the specified condition.
1-23 34 Write a program to remove all comments from a C program. Don't forget to handle quoted strings and character constants properly. C comments do not nest.
1-24 34 Write a program to check a C program for rudimentary syntax errors like unbalanced parentheses, brackets and braces. Don't forget about quotes, both single and double, escape sequences, and comments. (This program is hard if you do it in full generality.)
Chapter 2
Number Page Prompt
2-1 38 Write a program to determine the ranges of 'char', 'short', 'int', and 'long' variables, both 'signed' and 'unsigned', by printing appropriate values from standard headers and by direct computation. Harder if you compute them: determine the ranges of various floating-point types.

tcpl's People

Contributors

twcarbone avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.