c - Most efficient way to replace a line in a text document ? -


i learning code in unix c. far have written code find index of first byte of line want replace. problem sometimes, number of bytes replacing line might greater number of bytes on line. in case, code start overwriting next line. came 2 standard solutions:

a) rather trying edit file in-place, copy entire file memory, edit shifting bytes if necessary , rewriting file.

b) copy line want end-of-file memory , edit.

both suggestions doesn't scale well. , don't want impose restrictions on line size(like every line must 50 bytes or something). there efficient way line replacement ? appreciated.

copy first part of file new file (no need read memory). then, write new version of line. finally, copy final part of file. swap files , done.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -