Read the entire contents of a file to c char *, including new lines

后端 未结 4 1897
孤城傲影
孤城傲影 2021-01-25 13:53

I\'m looking for a cross platform (Windows + Linux) solution to reading the contents of an entire file into a char *.

This is what I\'ve got now:



        
4条回答
  •  旧时难觅i
    2021-01-25 14:20

    fread reads all the files as-is:

     if (fread(contents, 1, fileSize, stream) != fileSize) {
        /* error occurred */
     }
    

提交回复
热议问题