C fread not getting entire file

前端 未结 1 1071
逝去的感伤
逝去的感伤 2021-01-21 14:47

I am trying to read binary files and storing the content into a char array. This function is working great for text files, but for non-text files (a PNG file for example) it doe

1条回答
  •  鱼传尺愫
    2021-01-21 15:13

    The strlen function is exclusively for use on C-style strings. There is no way to tell the length of arbitrary binary data by looking at its content. You have the length in lengthRead.

                fprintf(stderr, "Content read:\r\n%s\r\n", *contents);
    

    Same problem here. The %s format specifier is for C-style strings, not arbitrary binary data. You'll need to write your own function to print the data in some appropriate format.

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