Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File handling with c

Status
Not open for further replies.

teekkari

Programmer
Dec 29, 2003
2
FI
Hi!
My problem is this:
I have a text file with the following content:

4 koira dog
7 keppi stick
4 lehti leaf
9 kissa cat
6 pallo ball

I want to remove one line from the text file with my c code:

void DeleteWord(char word[40], FILE *in) {
tests if the word is in the file;
deletes the line that containes word[40];
}

if I remove the line with "lehti", the result would be:

4 koira dog
7 keppi stick
9 kissa cat
6 pallo ball

I couldn't find any functions that does this in c. Any ideas?
 
You will need to do the following;

(1) Open text file for reading.
(2) Create a new file
(3) Copy from file (1) to file (2) excluding the line that contains the string to you want to excluded. You can use the "strstr" function to check whether the line includes the string.
(4) Rename the file create in (2) to the name of file (1).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top