Is it safe and acceptable to opening a file and immediately close it to simply remove its contents.
FILE *fp = fopen("file_name.dat","w");
fclose(fp);
I try it and works fine for me. what is recommended method? Please explain other way(s) of doing it. Not duplicate of truncate file I want to know is this way to remove a file true because I guess it and not read it in any books
There are multiple ways you can achieve it. It all depends on your use case. Few of them are as follows:
FILE *fp = fopen("file_name.dat","w"); /*fopen("file_name.dat","wb");*/
if(fp)
{
fclose(fp);
}
It is better to check for the fopen
return.