How to read a binary file in c? (video, images, or text)

前端 未结 3 1619
慢半拍i
慢半拍i 2020-12-05 16:35

I am trying to copy a file from a specified library to the current directory. I can copy text files perfectly. Any other files become corrupt. The program detects a feof bef

3条回答
  •  借酒劲吻你
    2020-12-05 16:53

    You need to specify the "b" option to fopen:

    source = fopen("./library/rfc1350.txt", "rb");
    ...
    destination = fopen("rfc1350.txt", "wb");
    

    Without it, the file is opened in text ("t") mode, and this results in translation of end-of-line characters.

提交回复
热议问题