Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check a file is opened or not if i forgot to assign null to file pointer

Tags:

c

file-io

I have opened a file

FILE *fp = fopen("file.txt","r");
fclose(fp);

scenario is that I forgot to assign null to fp Now I want to check whether this file is open or not using same fp pointer

like image 761
Avinash Kumar Avatar asked Feb 13 '23 22:02

Avinash Kumar


1 Answers

You can't. The value of fp after closing it is indeterminate: http://www.iso-9899.info/n1256.html#7.19.3p4

This means any operation on it results in undefined behaviour.

like image 59
Brave Sir Robin Avatar answered Apr 27 '23 09:04

Brave Sir Robin