char array is being assigned a vlaue when it should not.

Started by
11 comments, last by Temrek 18 years, 5 months ago
The file looks exactly like engima figured out (except replace something with NULL).

I got it to work better now, but it does not work as it is supposed to.

BTW I am using structs.

It never seems to detect eof.

		if (file.eof() == true || times == 9)	{		break;	}


The output I get is right except it does not stop when it is supposed to.
Advertisement
When you say "replace something with NULL", do you mean that the actual text "NULL" appears in your file, or that there is *nothing there* (i.e. the line starts with the file name)? That way would explain everything: what happens is that the file name gets read when it looks for "collisionMap", and then the first number gets read (as text) when it looks for the file name, and then eventually it reads the file name on the *next* line as the last number (because that's the next token in the file when it gets to that point).

I would strongly suggest that you (a) put the 'collisionMap' label on its own line (assuming it's really needed at all?) and (b) be more careful about how you handle reading it - you should not "try" to read it in each line.

As for eof(), it does not return true until you have already tried to read past the end. The stream does not magically know "there is no more data" until it tries to read something and finds out that there is no more data. You will need to Think(TM) to design around this.
I meant I write NULL in the file (that data is read but not used, hence null, I could do without not actually writing anything though).

By the way I got it to work completly as I want to, thanks for all your help!

This topic is closed to new replies.

Advertisement