Advertisement

Loading chars[]...

Started by May 21, 2002 12:27 PM
13 comments, last by Ragadast 22 years, 7 months ago
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?
It''s \n not /n
Advertisement
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.
I tried ''\n'' with and without quotes and it didnt work
The easiest way to do what you want (convert the \n''s in the file to new lines) is the following:


  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 %).
Ha. What am I, nuts? That totally doesn''t work.
Advertisement
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.
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?
Or could always do something cheesy but simple like use ~ to represent a carriage return in the text file and then go through each line when you read it in ''n replace all the tildes with \n...

This topic is closed to new replies.

Advertisement