会发生什么文件被关闭后,文件指针? [英] What happens to FILE pointer after file is closed?

查看:420
本文介绍了会发生什么文件被关闭后,文件指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道发生了什么文件被关闭后,文件指针。这将是空的?

I wish to know what happens to FILE pointer after the file is closed. Will it be NULL?

基本上,我想检查关闭文件之前,如果文件已经关闭。

Basically, I want to check if a file has already been closed before closing a file.

例如如下:

FILE *f;

if(f!=NULL)
{
  fclose(f);
}

我能做到这一点,或有任何其他方式去了解它?

Can I do this or is there any other way to go about it?

推荐答案

由于参数按值传递没有办法 FCLOSE 可以将您的文件指针设置为 NULL 。由于 FCLOSE 可能会破坏文件你必须

Since arguments are passed by value there is not way fclose could set your file pointer to NULL. Since fclose probably destroys the FILE you have to


  • 手动设置文件指针 NULL 操作后, FCLOSE (如果你关闭它不会工作unles您使用不同的功能文件**

  • 请不要在一个情况结束了,你在哪里的忘记的是否关闭与否(可能是棘手的)

  • Manually set the file pointer to NULL after doing a fclose (won't work if you close it in a different function unles you use FILE **)
  • Don't end up in a situation where you "forget" whether you closed it or not (might be tricky)

这篇关于会发生什么文件被关闭后,文件指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆