Skip to content
Advertisement

C Just Delete Some Part Of File

I have two files. I want to copy source file to destionation file. If they are different, then I just want to copy different line not all file. In the below case, two line are same, but destination has extra line. How can I just delete last line of destination file?

For example:

Source File:

test1  
test2

Destionation File:

test1
test2  
test3

Advertisement

Answer

On POSIX systems, if you want to delete some ending bytes in a file, you could use ftruncate(2)

There is no portable way to remove bytes in the middle of a file.

Advertisement