Menu

#635 fscanf fails to return a proper result

open
nobody
None
5
2012-09-26
2006-04-05
Anonymous
No

This is the code example:

FILE *f_Extract;
int nMagicByte = 0x0;

f_Extract = fopen("Dt021546.mde", "rb");
fscanf(f_Extract, "%d", &nMagicByte);

fclose(f_Out);

The file contains the following first bytes:
D8 00 01 00 00...

The variable MagicByte will not contain the expected
value 0xD800 (55,296 decimal).

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Surely it should return 0xd8000100 or 65755 as this is a
    32bit request?

     
  • Nobody/Anonymous

    Logged In: NO

    Program is flawed.

    The fscanf function converts from text representations so MagicByte would only contain 55,296 if the file started with the ASCII string "55296". As it is MagicByte will be set to 0 as the the 0xD8 character is not valid in a string that represents an integer.

    This is not a bug in Dev-C++ nor is it a bug in the underlying compiler, it is a fundament mistake in the program.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.