Suppose I have the following code :
FILE *x = fopen("story.txt",r);
if(x!=NULL)
{
x = fopen("story.txt",wb); /* <- Does this waste/leak memory ?? */
/* ... do something .... */
/* if(fclose(x)==EOF)...else... */
}
else
{
printf("story.txt does not exist\n");
}
Here, I'm reassigning the pointer to where a buffer for story.txtwas created in memory , without fclose(x) , assuming that since it is a pointer, the memory area will simply be overwritten to with the ' new ' buffer. Is this assumption accurate ? Am I leaking or wasting memory , or is the approach okay ?