开发者

After rewind(), can you make fprintf() write to end of file (e.g. complete overwrite)

In C, the rewind() call starts the next write at the front of the file.

As I understand it, when I call fprintf(), it will write to the end of the string I am trying to write and no further开发者_运维知识库. If the existing file has data past the end of the string I am writing, this is not overwritten.

Is there a way to change this behavior so that rewind() can be used to effectively perform a quick overwrite of the entire file?


If you want to truncate the file to zero length, reopen it in write mode. If you want to truncate it while it's open, ftruncate should do it in POSIX systems. There are, I believe, _chsize and _ftruncate in Windows, which are similar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜