Advertisement

string problems

Started by March 14, 2003 07:25 PM
1 comment, last by Brad8383 21 years, 8 months ago
This is probably something stupid im doing but here some code
for(int x = 0; x < 3;x++)
	{
		WorldMap.push_back(vector());
		for(int y = 0; y < 3; y++)
		{
			WorldMap[x].push_back(ms);
			char a[50];
			sprintf(a,"map%d%d.mp",x,y);
			WorldMap[x][y].MapName = a;
		}
	} 
Anyone see something that would make every member of worldmap = "map22.mp"
because you''re directly assigning the MapName to be a pointer to the locally declared array.

But... but that''s what HITLER would say!!
Advertisement
instead of
WorldMap[x][y].MapName = a; 

do this:
WorldMap[x][y].MapName = new char[strlen(a)+1];strcpy(WorldMap[x][y].MapName, a); 

This topic is closed to new replies.

Advertisement