How to insert a line of strings into a file at exact position

Hi everyone!
For example:
I have a file "data.txt" like this:
1
2
3
FIRST LINE
123 456 789
LAST LINE

Now I want to insert a string "NEW LINE" as a new line after line 2
The result will be:
1
2
3
4
FIRST LINE
123 456 789
NEW LINE
LAST LINE

The next question is how to replace the second line by a new line.
The result will be:
1
2
3
FIRST LINE
NEW LINE
LAST LINE

How to do this? (I'm using DevC++, programming C)
Thanks!
Last edited on
I would recommend opening the file and searching for the line using a loop, while the file is not at end of file search for this phase. when the phrase comes up replace that line and rewrite the rest.

Ill go more in depth after i get some rest(oh the irony)
Topic archived. No new replies allowed.