C Programming Homework #8: Reverse Words

Due: Monday, March 28, 2016

  1. Write a program that outputs every line of its input with the words reversed. For example, given a line such as:

      This is a message: Hello, World!

    The program should output the line as:

      sihT si a egassem: olleH, dlroW!

    Notice how each word (where "word" consists of a sequence of letters in either upper or lower case) is handled separately. The spaces and punctuation marks are not affected.

    Your program should read the entire line into an array, manipulate that array (or perhaps copy characters to a new array) and output the result. You can use either array indexes or pointers as you choose. You might consider writing a function that does the word reversing problem and then using that function. For example:

      void reverse_word(char line[], int start, int end);

    Here line is the array containing the line of text, start is index of the start of the word, and end is the index of the last character of the word (or maybe just past the word... whichever you find convenient).

Submit your program to Moodle (the .c file). Be sure it includes a comment block at the top that includes your name, the name of the file, the date, and a brief description of what the program does..

Last Revised: 2016-03-16
© Copyright 2016 by Peter C. Chapin <PChapin@vtc.vsc.edu>