cfile-io

How do I insert and delete some characters in the middle of a file?


I want to insert and delete some chars in the middle of a file.

fopen() and fdopen() just allow to append at the end.

Is there any simple method or existing library that allow these actions?


Solution

  • There is no simple method. You have do it manually. For example:

    1. Read the chunk you want to insert before into memory
    2. Seek forward to new position
    3. Write the chunk you just read at new position
    4. Seek back to where you want to insert
    5. Write the new data.