fclose(stdin);

Discussion in 'C Programming' started by viza, Jul 19, 2003.

  1. viza

    viza Guest

    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?
    viza, Jul 19, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve

    Ok to fclose stdin?

    Steve, Oct 24, 2003, in forum: C Programming
    Replies:
    2
    Views:
    1,429
    Steve
    Oct 24, 2003
  2. Johnathan Doe

    peek at stdin, flush stdin

    Johnathan Doe, May 15, 2004, in forum: C Programming
    Replies:
    5
    Views:
    24,818
    Chatoyer
    May 17, 2013
  3. Charlie Zender

    Reading stdin once confuses second stdin read

    Charlie Zender, Jun 19, 2004, in forum: C Programming
    Replies:
    6
    Views:
    764
    Dan Pop
    Jun 21, 2004
  4. Ben
    Replies:
    2
    Views:
    1,323
    jacob navia
    Aug 29, 2009
  5. Terry Cooper
    Replies:
    7
    Views:
    418
    Janos Sebok
    Jun 9, 2009
Loading...

Share This Page