Thread: String Formatting

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    38

    String Formatting

    Hi for school i need to make a code where i need to to enter a string between 150 to 200 characters and then specify how many characters i want per line. now im not allowed to split words so i'm required to add extra spaces so the there are enough characters.

    So far i know i knave to use strtok, but other than that i have no idea on how to go about the problem. I'm not asking for a solution, but some strategies on how to tackle the problem.

    Thank in Advance
    Spikestar

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    12
    If you choose to use strtok, you will be able to extract the words one by one. You'll want to keep track of the number of characters used up on the current line, and if that would be greater than the limit, print out a newline before printing the word. Watch out for input words which are larger than the line length potentially causing an endless loop though.

    You shouldn't have to print out extra spaces manually to force a newline, if that's what you were planning.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    38
    I got it working..
    Last edited by spikestar; 08-27-2009 at 01:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please check my C++
    By csonx_p in forum C++ Programming
    Replies: 263
    Last Post: 07-24-2008, 09:20 AM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM