Chapter 1 - A Tutorial Introduction
|Ex No||Pg No||Exercise||Solution||Solved by|
Run the "hello world" program on your system. Experiment with leaving out parts of the program, to see what error messages you get.
|Listing krx101||Richard Heathfield|
Experiment to find out what happens when
|Listing krx102||Richard Heathfield|
Modify the temperature conversion program to print a heading above the table.
|Listing krx103||Richard Heathfield|
Write a program to print the corresponding Celsius to Fahrenheit table.
|Listing krx104||Richard Heathfield|
Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0.
Category 0 Solutions by Richard Heathfield and by Chris Sidi.
Verify that the expression
|Listing krx106||Richard Heathfield|
Write a program to print the value of
|Listing krx107||Richard Heathfield|
Write a program to count blanks, tabs, and newlines.
|Listing krx108||Richard Heathfield|
Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.
Category 0 Solutions by Richard Heathfield, by Chris Sidi, and by Stig Brautaset.
Write a program to copy its input to its output,
replacing each tab by
A couple of solutions here. One from Richard Heathfield, and one from Gregory Pietsch.
How would you test the word count program? What kinds of input are most likely to uncover bugs if there are any?
|Listing krx111||Solution by Dann Corbit. Solution to Dann's follow-up challenge by Gregory Pietsch.|
Write a program that prints its input one word per line.
|Listing krx112||Richard Heathfield|
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.
|Listing krx113||Richard Heathfield|
Write a program to print a histogram of the frequencies of different characters in its input.
|Listing krx114||Richard Heathfield|
Rewrite the temperature conversion program of Section 1.2 to use a function for conversion.
|Listing krx115||Richard Heathfield|
Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text.
"386sx" and Richard Heathfield.
Write a program to print all input lines that are longer than 80 characters.
Write a program to remove all trailing blanks and tabs from each line of input, and to delete entirely blank lines.
Solution by Ben Pfaff, modification by Chris Sidi
Write a function
|Listing krx119||Richard Heathfield|
Write a program
|Listing krx120||Richard Heathfield & others|
Write a program
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 column.
Category 1 Solution by Rick Dearman
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.
This was the first exercise for which solutions were submitted en masse from comp.lang.c, and as a result, quite a few solutions have been provided here. You may find it interesting to compare and contrast different approaches to the same problem.
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.)
Solutions by Rick Dearman and others