开发者

How do I overwrite X bytes on offset Y with fwrite()?

开发者 https://www.devze.com 2022-12-26 18:52 出处:网络
All I can find using fopen() and fwrite() in C is to delete all contents and start writing again or append to the end of the file. What if I need to go to some offset in the file and overwrite a few b

All I can find using fopen() and fwrite() in C is to delete all contents and start writing again or append to the end of the file. What if I need to go to some offset in the file and overwrite a few bytes?

Is that possible with some functi开发者_Python百科on?


You can open the file with the "rb+" option and then use fseek with SEEK_SET to go to a specific location. Therb+ opens it for both reading and writing as a binary file (the file must exist in order for it to succeed - it will not create a new file).

0

精彩评论

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

关注公众号