Search code examples
cfilefopen

How to delete data from file and move all info back


I created a file with fopen and I deleted the first value from the file and I want to take all of the values that are in the file and move them to the start of the file.

Example:

  • File: [Info,data,string]

  • Wanted: [data,string,]

  • What is happening: [,data,string]

Any help will be great.


Solution

  • Then you have better to copy all data after the first byte into another file, then move that file into the original. There's no system call to delete some part of the file, and close the hole around the deleted data. The file internal structure is not suited to do that, and requires to copy/shift the whole file data to the proper place.