Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey friends
I have *file , I would like to cut the file by 2 another *file
I want just from the initial file extract the 3 first line and change its to another *file
-after I want delete the 3 first line from the initial *file
thnk for your help

What I have tried:

int _tmain(int argc, _TCHAR* argv[])
{
FILE *fpIn=fopen("file_initial",rb");
//create another fie
//extract the 3 first line and change o the file
//delete the 3 frst line from the initial fil
;
end
Posted
Updated 15-Jun-16 15:50pm

1 solution

The main thing you have to understand is: in general case, you have to rewrite the whole file. Why?

You will understand it if you look at the structure of the text file and understand what is "line". This is a string subdivided by end-of-line strings. If one of the strings to be replaced is shorted or longer than before the change, all the text after the change should be shifted in memory.

It the file is not very big, you can read it all in memory, and then change the lines you need to change, and write it back. If the file is too big to reliably fit in memory, read each line and write it in a new (temporary) file, changing required lines. When it's done, you can rename/move the temp file to the original file.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900