Loading chars[]...
I''m making a short text RPG and I load the rooms info from text files. I put all the room description in a single line, so It''s easy to read, but I get the problem when I cout it. For example:
Text file:
You are in a big square. You suddenly feel that....
And I want it to cout:
You are in a big square. You
suddenly feel that...
I tried putting ''/n'' after the "You", but it just outputs
"You ''/n'' suddenly feel that...". Is there a way to end the line after the "You" without making more lines of description in the text file?
Try ''\n''. Notice that''s a backslash, not a forward slash.
Also, before anyone gets a little violent about char []''s and strings, mebbe just have a look at std::string. Much easier to work with in most cases.
Also, before anyone gets a little violent about char []''s and strings, mebbe just have a look at std::string. Much easier to work with in most cases.
May 21, 2002 12:54 PM
The easiest way to do what you want (convert the \n''s in the file to new lines) is the following:
One caveat: you have to be careful about %''s in your string - they will be treated as format indicators. Just make sure you use two if you need one. (%% instead of %).
char readBuffer[512];char dispBuffer[512];fgets( readBuffer, sizeof(readBuffer), fp ); // read from filesprintf( dispBuffer, readBuffer ); // copy to new bufferputs( dispBuffer); // display buffer
One caveat: you have to be careful about %''s in your string - they will be treated as format indicators. Just make sure you use two if you need one. (%% instead of %).
May 21, 2002 12:59 PM
You''re probably going to need to put actual carriage return chracters in your text file and write your read in code as a loop. Sorry.
May 21, 2002 12:59 PM
You''re probably going to need to put actual carriage return chracters in your text file and write your read in code as a loop. Sorry.
I got an idea, but I need to know how to convert a char[] to a string. Any idea?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement