Odd result when reading first byte of a PNG header
I'm trying to read the header from a PNG file.
The result sho开发者_运维问答uld be
Dec: 137 80 78 71 13 10 26 10
Hex: 89 50 4E 47 0D 0A 1A 0A
However, I get
Dec: 4294967 80 78 71 13 10 26 10
What am I doing wrong?
Code:
char T;
pngFile = fopen(Filename, "rb");
if(pngFile)
{
fread(&T, 1, 1, pngFile);
fclose(pngFile);
printf("T: %u\n", T);
}
137 is too big for signed char - use unsigned char
instead...
see this link for limits of data types.
精彩评论