iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
first find out how many words are on the line, count the length of all the words. subtract that from the total line length and you get the number of spaces that you have to distribute between the words. divide that number by the number of words and you get the number of spaces you have to put between each word.
Example
"any text abouth 900 characters"
That contains 27 characters, not counting the spaces. If you want a line length of 40, you get (40 - 27) = 13 spaces that have to be distributed between the 5 words. Because there are no spaces after the last word, the 13 spaces have to be distributed over 4 areas, or 3 spaces between each word with 4 spaces between the last two words. That makes the final string look like this:
"any text abouth 900 characters"
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
use a data file that contains lots of words -- for example (USA) President's Lincoln's Gettysburge Address (you can use google to find it) or some other file you may already have on your computer. Read the file one word at a time, keep track of the total number of characters read (plus 1 for at least one space between words). When that sum >= 80 (or whatever number you choose) you know the last word read will not fint on the current line, so output all words and spaces read so far. You will have to use an array to hold the words that have been previously read.
Before you output the words, sum total length of the characters and substract from total desired line length. For example, if sum = 70 then 80 - 70 = 10. You will have to distribute 10 spaces between the words. If there are 6 words, then there will be 10/6 = 1 space between words, plus 4 spaces you will have to distribute between the first 4 words. So the first 4 words will have 2 spaces between them and the last 2 words will have only 1 space.
Once the number of spaces between words is derived the function can start outputting the line. start a loop
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
that was as specific as I'm going to get without actually coding the program for you.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
sen de mi brütüs!tum fatih universitesi burda olsa gerek!!!
Greek never was my strong subject.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115