How do I delete a line of text in a text file without deleteing the entire file? Would switching to binary mode and then back to text help?
Thanks
Jeff
How do I delete a line of text in a text file without deleteing the entire file? Would switching to binary mode and then back to text help?
Thanks
Jeff
Good question. You might try fputs with a whole slew of blank spaces. But, I don't think that'll work. And I don't know of any functions.
But try writing a lot of blank spaces to a line and see what happens.
--Garfield
1978 Silver Anniversary Corvette
You could read in the whole file, copy the text after the line to the line and shorten down the file.
Pseudo code:
data = FileRead(sizeof(file));
memcpy(&data[startofline], &data[endofline], sizeof(file)-endofline);
FileWrite(data, sizeof(file)-startofline);
// Gliptic
If you know the full line of text in the file, as gliptic says read file.
I would suggest using the original file and a new file. Even if you knew the first field was unique e.g. refernece number, you should be able to delete the relevant line accordingly
Ofcourse you will have to manipulate the code to your own specifications, new line characters ext.Code:old_fp = fopen("oldfile.txt", "r") new_fp = fopen("newfile.txt", "w") while((fgets(str, record_length, old_fp))!= EOF) { if(strcmp(known_textinfile, str)) { fputs(str, new_fp); } }
hoping to be certified (programming in c)
here's the news - I'm officially certified.