Reputation: 81
So I have a txt file that looks like this:
112 12.50 Y 15
267 7.75 N 20
382 15.50 N 45
User is prompted where he wants to insert a new ID. My job is to make the program write the new ID into the .txt file without totally overwriting all the information. Say the user wanted to insert the new ID after 267. The user tells me new ID is 123, 12.34, N, 12. The .txt file would have to look like this:
112 12.50 Y 15
267 7.75 N 20
123 12.34 N 12
382 15.50 N 45
Upvotes: 0
Views: 192
Reputation: 62058
In standard C there's no functionality to insert new data at a certain location within a file.
The only two options in plain C are:
There may be OS-specific functions to perform insertion of data at an arbitrary location within a file. But, again, not in the standard C library as defined by the C standard.
Upvotes: 3
Reputation: 25705
steps:
Upvotes: 2
Reputation: 70939
The only option that you have to add information in the middle of a file without overwriting old data is to move manually all the data following the position where you want to add into the file.
Upvotes: 2