Thread: Brief question about stdin

  1. #1

    Brief question about stdin

    Hey,

    I was wondering: If I use "fclose(stdin)" to deactivate keyboard input, how can I "reopen" stdin? I believe it has to do with fdopen().....?
    Last edited by B-Con; 05-30-2004 at 06:58 PM.
    "Cryptographically secure linear feedback shift register based stream ciphers" -- a phrase that'll get any party started.

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    Code:
    #include <stdio.h>
    
    int main(void) {
         int standard_input;
    
         standard_input = dup(STDIN_FILENO);
         fclose(stdin);
         fdopen(standard_input, "r");
         return 0;
    }
    dup:
    http://www.rt.com/man/dup.2.html
    fdopen:
    http://www.neosoft.com/neosoft/man/fdopen.3.html
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Do you ever take the time to try and research your questions C+++C_forever? Since these functions reside in stdio.h its a pretty good possiblity that they are standard.

  4. #4
    I get it now..... Much thanx
    "Cryptographically secure linear feedback shift register based stream ciphers" -- a phrase that'll get any party started.

  5. #5
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    The following are not standard:
    dup
    fdopen

    and the macro STDIN_FILENO

    In ISO C, you interact with files through objects of type FILE *, there are no functions involving file descriptors, file handles etc.
    The one who says it cannot be done should never interrupt the one who is doing it.

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Quote Originally Posted by Thantos
    Do you ever take the time to try and research your questions C+++C_forever? Since these functions reside in stdio.h its a pretty good possiblity that they are standard.
    Do you ever take time to research your answers, Thantos? If you had even glanced at the links provided, you would've realized that the dup() and fdopen() functions are not ANSI-compliant, but POSIX-compliant.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I looked up fdopen() on the man page and
    The fopen and freopen functions conform to ANSI X3.159-1989 (``ANSI C'').
    was tired and didn't realize that it didn't say fdopen(). Sorry was tired

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. stdin question
    By audinue in forum C Programming
    Replies: 12
    Last Post: 01-11-2009, 02:57 AM
  3. stdin question
    By SourceCode in forum C Programming
    Replies: 1
    Last Post: 04-10-2003, 08:50 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. stdin question
    By oomen3 in forum C Programming
    Replies: 6
    Last Post: 02-19-2003, 02:52 PM