SA-MP Forums Archive
fgetchar returning wrong data - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: fgetchar returning wrong data (/showthread.php?tid=523781)



fgetchar returning wrong data - Kwashiorkor - 03.07.2014

I got a problem using fgetchar to get data from a binary file. The content of the file is (only for testing, the real one is bigger)
Код:
44 21 3c da be 00 0a ff
Now i'm trying to read every byte using fgetcar. The result is
Код:
44 21 3c 1be 00 0a ff ffffffff
0xFFFFFFFF is EOF, the error seems to happen at 0xDA since replacing it with certain other values works - but then again with other values it doesn't work. Has anyone experienced strange behavior of fgetchar? The return value should be either EOF (end of file) or [0;0xFF], yet 0x1BE (446) is being returned.

//Edit: colorization of some values


AW: fgetchar returning wrong data - Nero_3D - 06.07.2014

The documentation of fgetchar is a bit vague, you need to use it like that with "0, false" to disable utf8 decoding
Quote:
Originally Posted by BigETI
Посмотреть сообщение
pawn Код:
#define freadchar(%0) fgetchar(%0, 0, false)
#define fwritechar(%0,%1) fputchar(%0,(%1)&0xFF, false)
Just quoted this from his topic "Binary file I/O in PAWN"


AW: fgetchar returning wrong data - Kwashiorkor - 06.07.2014

Oh, that's really strange. I disabled utf8 decoding by using fgetchar(handle, false) because https://sampwiki.blast.hk/wiki/Fgetchar says that it uses 2 parameters and the second one toggles the utf8 decoding. Having a look into the files.inc I realized it has 3 parameters. Well, thank you very much What does the parameter "value" mean btw?


AW: fgetchar returning wrong data - Nero_3D - 07.07.2014

I have no clue, also it doesn't affect anything