Do `fgetc`, `fputc`, `fgets` and `fputs` require a file opened in text mode, and `fread` and `fwrite` require a file in binary mode?

前端 未结 2 1201
清歌不尽
清歌不尽 2021-01-25 08:01

When using fgetc, fputc, fgets and fputs for a file, do I need to ensure that I have opened the file in text mod

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-25 08:48

    No. All stdio input and output functions are defined in terms of repeated calls to fgetc or fputc. Aside from POSIX requirements on top (mainly locking being for the whole larger operation rather than at the individual fgetc/fputc granularity), there is no difference between calling fputc or fgetc in a loop yourself, or doing the equivalent with fwrite or fread.

    If the C implementation you use treats text files differently from binary, that treatment applies no matter which functions you use to perform the operations.

提交回复
热议问题