Write to a file using fputs in C

后端 未结 2 1803
走了就别回头了
走了就别回头了 2020-12-17 10:24

Could someone tell me why the file doesn\'t change? It works when I use rewind or fseek but not otherwise.

What\'s the standard way of usin

2条回答
  •  醉酒成梦
    2020-12-17 10:41

    The MS documentation for fopen says this:

    When the "r+", "w+", or "a+" access type is specified, both reading and writing are enabled (the file is said to be open for "update"). However, when you switch from reading to writing, the input operation must encounter an EOF marker. If there is no EOF, you must use an intervening call to a file positioning function. The file positioning functions are fsetpos, fseek, and rewind. When you switch from writing to reading, you must use an intervening call to either fflush or to a file positioning function.

提交回复
热议问题