fclose(stdin);

V

viza

Hi!

Is there any harm/advantage to closing the standard input stream if I am not
going to read from it again?

I have:

if(blah)
fileptr=fopen(blah);
else
fileptr=stdin;

stuff;

if(fileptr!=stdin) /*this line*/
fclose(fileptr);

Can I just miss out the marked line and close whatever fileptr is?

Also, assuming I don't need the stream again, (and I can be reasonably sure
no other process will want it in the mean time) what reason is there to
close the file at all, as exit() will eventually close all open streams
anyway?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top