Addresses, Pointers, Arrays and Strings - Exrecises

Chapter chap6 section 16

  1. Write a program to read text lines into a buffer using gets(). Calculate the length of each line. By using input redirection arrange for your program to read a text file (such as its own source) and print out

    	The number of lines read
    	The length of the longest line
    	The length of the shortest line
    	The average line length
    

    You should arrange for a line of length zero to terminate your file.

  2. By using a text editor (or otherwise) create a file containing a significant number (80-100) integers in the range 0-100. Place the integer 999 at the end of the file.

    Write a program to read the file using input redirection and calculate the number of input integers in each of the ranges 0-9, 10-19, 20-29 etc., Print out the results of your calculations.

  3. Modify the program of the previous exercise to print out a histogram for each of the ranges consisting of a sequence of asterisks running across the screen.

  4. Modify the program of the previous exercise to produce a vertical histogram rather than a horizontal histogram.

  5. Write a program that will read text from standard input and produce a list of the characters encountered in the input and the number of times each character occurred. You will find it most convenient to use gets() to read each line of input into a buffer and terminate your input with an empty line. Run the program with input re-direction to read from a file. Do not print out the character and the count if it did not occur in the input.

  6. Modify the program of the previous exercise to print out the character frequency table in lines of not more than 8 entries going across the screen rather than one long list.

  7. Write a program that will prompt the user for two strings of characters, assemble them into a single string and then print the string out reversed.