关闭文件必须要检查文件指针吗?
int creat_file_char(FILE* tp)
{
return 0;
};
int main (void)
{
FILE* tp = NULL;
tp = fopen("c:/text/text2.txt", "w");
if (tp = NULL)
{
fprintf(stderr, "fopen file error");
return -1;
}
else
printf("open file succ!");
if (tp != NULL) //这里一开始没有加这句,然后运行后就出了一大堆英文的,好像是操作错误之类的
。 {
fclose(tp);
}
return 0;
}
特别简单的一个打开文件,但是我一开始的时候没有加if (tp != NULL)。然后运行后就出了一大堆英文的,好像是操作错误之类的。加上就没事了,是为什么????