building filenames on the fly

Started by
1 comment, last by sipickles 18 years, 10 months ago
Hi, I am a little puzzled on how to build filenames as a function runs. I am trying to pass a base filename to a function, then load filename_1, filename_2 etc
Cworld::Cworld( LPDIRECT3DDEVICE9 _Device, CHAR* filename, int _numSectors )
{
	m_lpDevice	= _Device;
	m_iNumSectors	= _numSectors;

	for ( int i = 0; i < m_iNumSectors; i++ )
	{
		char		sectorFilename[64];
		sprintf(sectorFilename,"data/terrain/%c_%i.x", &filename, i+1 );

		//do stuff
	}
}
however this isnot quite working, the char* isnt being converted into the string in the filename. eg output is "data/terrain/$_1.x" Can anyone help? Thanks in advance
Advertisement
Hi,

Use this instead:

sprintf(sectorFilename,"data/terrain/%s_%i.x", filename, i+1 );

%s -> String.
& -> You don't need it since filename is already a char*.
Thanks for clarifying....

thought i'd tried that but must;ve been going round in circles!

This topic is closed to new replies.

Advertisement