In main I create a file pointer, pass that to a function to open it and I want to have a separate function to close the file but I am not able to close the file. What am I missing?
I do not get an error but the way that I am checking indicates the files did not close.
thanks for help on this.
int _tmain(int argc, _TCHAR* argv[])
{
FILE *inFile, *outFile;
FileOpen(&inFile, &outFile);
FileClose(&inFile, &outFile);
getch();
return 0;
}
void FileOpen(FILE **inFile, FILE **outFile)
{
//--Open InFile--------------------------------
if ((*inFile = fopen("a.txt","r")) == NULL){
printf("\nError Opening File. ");
exit(0);
}
else {
printf("File Opened\n");
}
//--Open OutFile--------------------------------
if ((*outFile = fopen("b.txt","w")) == NULL){
printf("\nError Opening File. ");
exit(0);
}
else {
printf("File Opened\n");
}
}
void FileClose(FILE **inFile, FILE **outFile)
{
//--Close InFile----------
if (fclose(*inFile)){
printf("File Closed\n");
}
else {
printf("\nError Closing InFile File. ");
}
//--Close outFile---------
if (fclose(*outFile)){
printf("File Closed\n");
}
else {
printf("\nError Closing OutFile File. ");
}
}