workwork
workwork

Reputation: 31

Insert (not overwrite) to file in C

In C, I'm using fseek to go back to a position in the file. When I then write to the file with fprintf, it overwrites the characters at that location. Is there a way to make fprintf/another function insert, instead of overwrite?

Thanks

Upvotes: 1

Views: 1118

Answers (2)

Marc B
Marc B

Reputation: 360592

No. C has no concept of "file insertion". You'll have to manually create a 'gap' in the file by copying all the data that comes AFTER your insertion point to a spot farther down the file.

Upvotes: 0

FatalError
FatalError

Reputation: 54551

The short answer is "no". If you need to insert, you really need to rewrite the entire file after the insertion.

Upvotes: 5

Related Questions