Hello,
I have some homework and I needed some help with finishing my code.
The question is this:
Create a program that reads a text file, named intext.txt, and writes an edited version of the file, named outtext.txt. The output file will contain the same text but each line will be as long as possible but not longer than a user specified maximum length that would be typed in from the keyboard. Words are added to the line until the addition of the next word would produce a line longer than the maximum length. This will create columns of text in the output file.
My code reads all of the words individually from the text file but I want it to read up to the word which are in the set boundaries. (so in my case one sentence will contain 20 characters or less depending on the next word.)
An example of what the output should look like is this,
Maximum length: 20 //not worried about this part yet
Create a program
that reads a text
file and outputs an
edited version of
the file.
Just to make it easy my file text contains the same text as the example I gave above.
My code:
You read (next) word. You do know its length.
You have a sentence. You do know its length.
If appending the current word would make the sentence too long, then you print the sentence and clear it.
Append the word to the sentence.
Rinse and repeat.
Hello so quick update I am able to make each sentence a set number of words. I can't figure out where I need to add an end line to create a new line that will work for the code. Due to the while loop it is creating a new line after each word.
This is my current code. I am close to being done if someone can please guide me.