By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

Destroying files in C

P: 34
Hi,
I am working in Windows XP and I need to destroy a file in a C program (not just erase its contents). The file was opened this way:

Expand|Select|Wrap|Line Numbers
  1. FILE* pBinFile = fopen(nameBinFile,"w+b");
  2.  
After that, I write data into the file. Finally, I try to destroy it with these instructions:

Expand|Select|Wrap|Line Numbers
  1. remove(nameBinFile);
  2. fclose(pBinFile);
  3.  
But the only effect is erasing the file's contents. How can I destroy it effectively?
Nov 1 '06 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 1,510
try closing the file then removing it, e.g.

fclose(pBinFile);
remove(nameBinFile);
Nov 1 '06 #2

P: 34
It worked!! Thanks a lot!!
Nov 1 '06 #3

Banfa
Expert Mod 5K+
P: 8,916
If this is a security program, writing data to the file will not destroy the contents it will still be recoverable. You need to make sure you have inerted all the bits of the file several times and then write a random pattern to the file.
Nov 1 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.