false mode w
w Create for writing. If a file by that name already exists, it will be overwritten.
is better
Code:
FILE *fp;
fp=fopen("filename.txt","r+"); //Open an existing file for update (reading and writing).
if(fp==NULL) //If a file by that name NO exists!!....Create
{
fclose(fp);
fp=fopen("filename.txt","w");
}
//insert code here
//no forget
fclose(fp);