Thread: word wrap part 2

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    8

    Talking word wrap part 2

    First one was too big and confusing.

    The assignment requires that I create a function which has the following input:

    original string
    output string
    output max length
    indent length
    line length

    the output string needs to be formatted in this manner:

    1)every line indented with the amount of spaces specified in the indent length variable
    2)all extra spaces ("I like to eat pie") removed ("I like to eat pie")
    3)all unprintable characters ('\a', '\b', '\f', '\r', '\t') removed
    4)newline created every line length
    5)any words which don't fit into the first line is moved to the second.

    ex:
    r=wordWrap("the quick brown \t fox jumped over the lazy dog",s,149,3,12);

    After the function call: r=any non zero value, and
    s=" the quick\n brown fox\n jumped\n over the\n lazy dog\n"

    I can remove all unprintable characters, but I have trouble with the extra spaces. I don't even want to think about how to read a word, store it to memory, then write it into the string, then continue.

    I have an idea how to do some of the things I listed, but I'd appreciate any help.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    8
    I got an idea. Using stringname.insert(location, string), I could put \n characters wherever they are needed. If you can provide any assistance with this approach I will appreciate it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hangman game and strcmp
    By crazygopedder in forum C Programming
    Replies: 12
    Last Post: 11-23-2008, 06:13 PM
  2. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Word wrap
    By Orrill in forum C++ Programming
    Replies: 6
    Last Post: 10-14-2005, 02:00 PM