Jump to content

  • Log In with Google      Sign In   
  • Create Account


loading/filename problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Bezzant   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 October 2001 - 07:48 AM

quick question... im in the process of writing what would seem like a text engine for a text adventure or whatever it gets turned into (if anything) i can load files ok, but just ran into a small problem.... i got a struct for PLAYER that stores player info and his/her current x and y position on the map (an array)... well when they move i need to load a file, this file needs to match where they are on the map.... so i thought that the easiet way to go about that would be creating files that have file names like this: 1.2.dat where the 1 and the 2 are the x and y pos on the map for where they load thus, when the player moves north, i update their position on the map and then want to load the file at there new position... so basically, PLAYER.X"."PLAYER.Y".dat" BUT, heres my file loader
  
void LoadMapArea(void)
{
	char ch;
	int mode = ios::in;
	char AreaFilename[20]= //problem here ;

	fstream fin(AreaFilename, mode); //input file

	while(fin.get(ch)) //read ch

{
	cout<<ch;          // print ch

}
	fin.close();       //close file

}
  
this line here is the problem: char AreaFilename[20]= well, i need to get it to = PLAYER.X.PLAYER.Y.dat.... but whatever i try i get errors because it cant convert int to char. so i need an alternative method... any help would be great, thanks for your time! Alan

Sponsor:

#2 VolkerG   Members   -  Reputation: 151

Like
Likes
Like

Posted 13 October 2001 - 08:11 AM

Here a quick and dirty solution:
  
char AreaFilename[20];
sprintf (AreaFilename,"%u.%u.dat",PLAYER.X,PLAYER.Y);

The format string of sprintf is the same as the one of printf. When using it this way, you must ensure that your string buffer is large enough.

#3 Bezzant   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 October 2001 - 09:37 AM

thanks, that works great!

thank you




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS