Hi all,

In my application i will be writing data to a text file periodically (assume every 5 min.)
after some time i want clear the old contents without halting the application and with out deleting the file.

thanks in advance
johny

Recommended Answers

All 6 Replies

> and with out deleting the file.
What's this supposed to mean?

Or more to the point, what's a "clean" text file with anything other than zero bytes in it supposed to look like?

When ready to clear the file out just close it and reopen with the truncate flag.

Hi,
I will be writing data to text file continuously ( assume 4-5days)
eg: file name johny123.txt
and data will be keep on appending to the text file.
on 2nd day I want to delete ( clear ) the contents of 1st day.
using C code I am clear when to clear the file, but i am not clear how to clear the contents of text file partially.
so that memory of text file will be reduced.

Thanks in advance

> and with out deleting the file.
What's this supposed to mean?

Or more to the point, what's a "clean" text file with anything other than zero bytes in it supposed to look like?

re-read my post -- all you have to do is close the file then reopen it with "w" flag. Pretty simple stuff.

hiya it just opens the file and if it fails to do so reports an error message.

thanks for the last bit of advice Aia

timestamp your logs by date (or week, month, etc.) then you can delete the old ones at your leisure.

you can keep the most current log name without a timestamp if you like, then before creating a new one the next day (or week, month, etc.) just rename it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.