This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Trouble with fscanf


Trouble with fscanf

Postby DillRye » Jul 10, 2002 @ 11:13pm

User avatar
DillRye
pm Insider
 
Posts: 477
Joined: Apr 25, 2002 @ 7:28am
Location: Iowa State University of Eng


Postby Digby » Jul 11, 2002 @ 1:45am

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.
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby DillRye » Jul 11, 2002 @ 2:06am

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?
User avatar
DillRye
pm Insider
 
Posts: 477
Joined: Apr 25, 2002 @ 7:28am
Location: Iowa State University of Eng


Postby Digby » Jul 11, 2002 @ 2:56am

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.
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby Digby » Jul 11, 2002 @ 6:51am

Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby RICoder » Jul 11, 2002 @ 6:57am

<iframe src="http://gamercard.xbox.com/RICoder.card" scrolling="no" frameBorder="0" height="140" width="204">RICoder</iframe>
User avatar
RICoder
FOX News Correspondent
 
Posts: 3948
Joined: Jul 10, 2001 @ 1:48pm
Location: the matrix has me


Postby DillRye » Jul 11, 2002 @ 6:58am

User avatar
DillRye
pm Insider
 
Posts: 477
Joined: Apr 25, 2002 @ 7:28am
Location: Iowa State University of Eng


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum