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

后端 未结 4 1894
孤城傲影
孤城傲影 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条回答
  •  星月不相逢
    2021-01-25 13:55

    The function fread will read from the stream and not terminate on end-of-line characters.

    From the man page, you have:

    size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);
    

    which reads in nitems of size size.

提交回复
热议问题