Hi all. First post on the forum.
I'm writing a generic funtion to open files along my program, but am worried if the pointers are being closed correctly.
The function definition:
FILE* openfile(char *FileName, char *Mode)
{
FILE *TempFile;
if((TempFile = fopen(FileName, Modo)) == NULL)
{
fprintf(stderr, "Couldn't open file '%s'. Does it exist? Do you have permission to read it?\n", FileName);
exit(1);
}
return(TempFile);
}
Calling the function in main:
int main(int argc, char **argv)
{
/* blahblahblah */
FILE *thefile;
char *thefilename;
thefilename = argv[1];
thefile = openfile(thefilename, "r");
/* uses the file */
fclose(thefile);
return(0);
}
What I'd like to know is if fclose(thefile) is closing all references to the file opened. That's because in the function we have TempFile actually opening the file. Is TempFile's reference also being closed when we call fclose(thefile) in main?
Thanks a lot.