ftell error after the first call to fread

后端 未结 2 1321
后悔当初
后悔当初 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.

提交回复
热议问题