Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - freopen() for redirecting needs fclose()?

Tags:

c

After a call like freopen(file_name, open_mode, stderr), do I need to call fclose(stderr) before the process ends or it is done automatically ? thanks in advance and sorry for my English

like image 654
user2302585 Avatar asked Oct 19 '25 05:10

user2302585


1 Answers

It is not necessary to close an open stream as all open streams are closed at program termination but it is good practice to have a fclose for every fopen call. In the case of stderr here, this stream is already open at startup (you didn't have to call fopen) and so I see no reason to explicitly close it even if some freopen calls were issued.

like image 189
ouah Avatar answered Oct 21 '25 19:10

ouah