在 main 中,我创建了一个文件指针,将其传递给一个函数来打开它,我想要一个单独的函数来关闭文件,但我无法关闭文件。我错过了什么?
我没有收到错误,但我检查的方式表明文件没有关闭。
感谢您对此的帮助。
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. ");
}
}