Page 1 of 1

Trouble with fscanf

PostPosted: Jul 10, 2002 @ 11:13pm
by DillRye

PostPosted: Jul 11, 2002 @ 1:45am
by Digby
What is fscanf returning when you try to read level[0][0] from the file?

Is fscanf actually writing the value 0 into level[0][0], or is the array initialized to zero and fscanf is writing nothing?

I wouldn't be surprised if fscanf is getting screwed up with what is normally referred to as 'whitespace' characters. I learned years ago to never use the scanf family of functions because they would fail and you never knew what was left in the input stream, or what the function decided to pull out or skip over.

With what you're trying to do I would just read the file into a buffer and use strtok/atoi to read the values.

PostPosted: Jul 11, 2002 @ 2:06am
by DillRye
When I read level[0][0] from the file it actually returns 0, I know this because I can preset level[0][0] to a number such as 5 and it will overwrite it(to zero) if I do it in the beginning of the function. Im guessing your right, it cant read the whitespace right, thing is I still want a user editable file.

I honestly have never used any file input functions besides the built in fscanf(C) or iostream(C++ and doesnt seem to be in EVC) stuff. I was wondering what file input functions you would reccomend?

PostPosted: Jul 11, 2002 @ 2:56am
by Digby
Well if you want to track down the problem a bit more, change your format string in fscanf to %c and see what character is read from the beginning of the input stream.

If I were doing this I would read the entire contents of the file (using CreateFile/ReadFile) into a buffer and then parse the buffer using strtok and atoi to read the integer values.

PostPosted: Jul 11, 2002 @ 6:51am
by Digby

PostPosted: Jul 11, 2002 @ 6:57am
by RICoder

PostPosted: Jul 11, 2002 @ 6:58am
by DillRye