   loading problem
  I''m trying to load a name of a file from another file but it''s not loading properly.  i''ve been looking over it for a while and i can''t see the problem so could someone else please have a quick look over this code and tell me the problem.the proplem is with TileSetLocation which is a char * TileSetLocation; and it is set to NULL in the constructor.also the writing to the file first is only temporary till i get my level editor working.bool CTerrain::Load(char *FileName){FILE *Load;dint Temp=150;dint Temp2=150;double Moose=0;dint size=8;Load = fopen(FileName,"wb");fwrite(&size,sizeof(dint),1,Load);fwrite("Temp.set",sizeof(char),size,Load);fwrite(&Temp,sizeof(dint),1,Load);fwrite(&Temp2,sizeof(dint),1,Load);    for(dint indx=0;indx<(Temp*Temp2);indx++){Moose = FRAND*(FRAND);    fwrite(&Moose,sizeof(double),1,Load);if(Moose < 0)Moose = 0.3;else Moose = 1;fwrite(&Moose,sizeof(double),1,Load);fwrite(&Moose,sizeof(double),1,Load);fwrite(&Moose,sizeof(double),1,Load);}fclose(Load);FILE *LoadTerrain;double TempX=0;double TempZ=0;dint Counter=0;dint LengthOfName;LoadTerrain = fopen(FileName,"rb");if(LoadTerrain == NULL)throw "ERROR: Failed To Load Map File";// Load in the length of the TileSet Locationfread(&LengthOfName,sizeof(dint),1,LoadTerrain);// Set aside memory for TileSetLocation TileSetLocation = new char[LengthOfName+1];// Load in the locationfread(&TileSetLocation,sizeof(char),LengthOfName,LoadTerrain);// Load in the map dimensionsfread(&NoVertexX,sizeof(dint),1,LoadTerrain);fread(&NoVertexZ,sizeof(dint),1,LoadTerrain);// Make sure something supid wasn''t loadedif((NoVertexX < 50 || NoVertexZ < 50)||   (NoVertexX > 150 || NoVertexZ > 150))throw "ERROR: Invalid Map Size";if(VertexData != NULL || ColourData != NULL)throw "ERROR: Level Data Not Ready For Loading Call UnLoad() First";VertexData = new double[NoVertexX*NoVertexZ][3];ColourData = new double[NoVertexX*NoVertexZ][3];for(dint indx=0;indx<(NoVertexX*NoVertexZ);indx++){// Load in the height at each vertex.// X and Z points are always the same so they are generated not loadedfread(&VertexData[indx][1],sizeof(double),1,LoadTerrain);// Height(Y axis)fread(&ColourData[indx][0],sizeof(double),1,LoadTerrain);// Rfread(&ColourData[indx][1],sizeof(double),1,LoadTerrain);// Gfread(&ColourData[indx][2],sizeof(double),1,LoadTerrain);// B}    fclose(LoadTerrain);ofstream File("HI.txt");File <   
  opps sorry about double posting it came up with a thing said it didn''t work or something. ;  You can delete your double posts by editing them, there will be a check box in the top to allow you to delete.What''s the error you''re getting, exactly?-fel ;  the other post was already deleted anyway.the error in my game or what it said when i posted?   [edited by - hello_there on February 1, 2004 11:07:53 PM];  oh you have to do it like this char *name = "Temp.set"; fwrite(&name,sizeof(char),size,Load); ;  i think maybe "Temp.set" is 9 in size not 8 since there is a null terminator at the end ;  umm, when you load the file name from the file fread won''t null terminate it, so you''ll get the name + a whole load of rubish at the end (to check this try printf''ing it to the console or something [DebugOutput under windows will go to the debugger''s console]). To resolve this try:fread(TileSetLocation, sizeof(char), LengthOfName, LoadTerrain);TileSetLocation[LengthOfName] = 0; // null terminate the string  (Incidentally, why did you do address of TileSetLocation in the fread ? TileSetLocation is a char * & so is already a pointer, what you technically tried to pass was a char** ... although I suspect the compiler straightened that particular case out for you ...) 