ftell error after the first call to fread

后端 未结 2 1313
后悔当初
后悔当初 2021-01-23 18:07

So I have a very simple program that reads the 3 first bytes of a file:

int main(void)

{

    FILE *fd = NULL;
    int i;
    unsigned char test = 0;
    fd = fopen(         


        
相关标签:
2条回答
  • 2021-01-23 18:44

    You need to open the file in binary mode:

    fd = fopen("test.bmp", "rb");
    

    If you try to read a binary file like a bitmap in text mode, the bytes corresponding to carriage returns and linefeeds confuse things.

    0 讨论(0)
  • 2021-01-23 18:49

    Please look at this question Reading bytes from bmp file.

    Looks like problem is in the mode of opening it.

    0 讨论(0)
提交回复
热议问题