开发者

updating a binary file without overwriting it -> C

开发者 https://www.devze.com 2023-02-05 16:33 出处:网络
I am trying to update a binary file that has inside some of these structures: typedef struct _test{ char question[100];

I am trying to update a binary file that has inside some of these structures:

typedef struct _test{
char question[100];
char answer[100];
}test;

At some point, I want to update one of the answers that is kept inside of a file to another answer (writing back again the answer to the file), still, ev开发者_开发技巧erytime I update the file it will erase everything and write only the new test structure (tried in fopen with modes wb, wb+ and even wa+ and settinng the cursor with fseek but no luck).

How can I edit the file so it doesn't wipe the entire file?


Use fopen("myfile.txt", "r+b").

0

精彩评论

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