Ok so I am at a point in making dialogue in my c++ game. Lately I have been searching extremely for a way to parse a text file(as an example one line) and form it into a proper paragraph(one that does not cut off the text mid-word)
an example would be:
1 2 3 4 5 6 7
Correct:
This is a
paragraph.
Incorrect
This is a par
agraph.
I guess a way to limit the size of the line would be by character number, like having a certain amount of characters allowed on one line then making the next.
I am pretty sure this is possible. If not with simple c++ then maybe a library that can do it for me.
I just feel that counting each character then putting '\n' in the right place might be a bit much when making a game with quests and such.
It depends on what exactly you're trying to do - for a console game - most shells already do this, some don't. You're probably out of luck trying to do something here.
For a more 'graphical' kind of game (which could include console games if you're actually using a console lib) - you can just form some rules on how to split sentences into parts after which line breaks may occur, determine how much room you have per line at runtime, and then determine the length of these parts at runtime. Then just fit as many of them into one line as possible.
I think I get what you are saying, and with that I have an idea.
What if I read the file word-by-word(all on one line, seperated by spaces) and at the same time counting the number of characters accumulated. and if the character number of the currently read word is over the limit per line, insert '\n'(making it a new line) and continue there.
I feel I can accomplish this but I would need to know how I would read each word and store it in a variable(at the same time counting the character amount), to later put them all together along with the needed spaces and line breakers to form the paragraph in one single string(the end result of all this should be a string to display the text in the game)
some sample code would help very well in this situation, just enough so I know how to store each word
Oh man thank you so much! With the help of the link and another thread i found shortly after, I got the paragraphs working exactly the way I want. Again thanks! :D