Skip to main content
gamedev.net
🔒 Locked

File I/O Problem

Started by Feblex Apr 16, 2003 at 10:37 PM 6 replies 250+ views
Original Post
Feblex
Feblex
Hmm, I think I''m doing this incredibly wrong, but if anyone can look over my code, I''d be much obliged.

bool LoadMap(void)
{
	
struct tile {
	int ID[10];
	int Special;
} Tile;

	int i;

	int Building;
	int LocX;
	int LocZ;

	int Models[7]; 

	int x = 0;

	char path[6] = ".msd3";

	FILE *mapFile;
	mapFile = fopen("map.txt", "r");

	while (fscanf(mapFile, "%d", &i) != EOF)  {
			Tile.ID[x] = i;
			x++;
	}
	
	for (x = 0; x < 7; x++) {
		Building = Tile.ID[x];
		char BuildingID = static_cast(Tile.ID[x]);
	
		LocX = Tile.ID[x+1];
		LocZ = Tile.ID[x+2];

		MS3D Building;
		Building.Load(BuildingID);



		x += 2;

	}

		return true;
	}

 
Basically, I''m opening a file, parsing each 3 lines into specific variables, and loading a Milkshape model. However, I keep getting asked to use a pointer as my filename (BuildingID). Whenever I do, I get an Assert failure in Valid_Block_Type_Header. What am I doing wrong?!
Feblex
Feblex
I figured that''d be a problem, but I wasn''t going to worry about it until I got it working by itself. Will that fix the Assert failure? I''m assuming the major problem is how to static_cast to a pointer, or whatever.
Feblex
Feblex
The reason I didn''t have it like you did was because it wasn''t working, and was giving me Assert failures. I just left it as a static_cast because I had no clue what to do
Feblex
Feblex
ARGHH!! I'm still getting Assert failures. I keep getting them in dbgdel.cpp- something I presume is a compiler thing?


bool LoadMap(void)
{

struct tile {
int ID[10];
int Special;
} Tile;

int i;

int Building;
int LocX;
int LocZ;

int x = 0;

char path[6] = ".msd3";

FILE *mapFile;
mapFile = fopen("map.txt", "r");

while (fscanf(mapFile, "%d", &i) != EOF) {
Tile.ID[x] = i;
x++;
}

for (x = 0; x < 7; x++) {
Building = Tile.ID[x];
char *BuildingID = reinterpret_cast<char *>(Tile.ID[x]);

LocX = Tile.ID[x+1];
LocZ = Tile.ID[x+2];

MS3D Building;
Building.Load(BuildingID);



x += 2;

}

return true;
}


[edited by - Kylotan on April 19, 2003 12:47:00 PM]
Kylotan
Kylotan
Why would you need a char*, pointing to an integer? And then pass that to a function? That looks very wrong to me,and I''m guessing that''s where the error is. Also, that x += 2 thing in the loop is confusing. Shouldn''t you just have x += 3 in the for statement?

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.