Thread: stdin

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    84

    stdin

    Hi Guys,

    Code:
    fgets(buf,5,stdin);
    The 3rd parameter in fgets is expecting a pointer to a file.
    When we want to get a safe input from the user to a buffer we use stdin instead.

    What is "stdin"?
    Where doe's it point to?

    THANK YOU!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    stdin is a "predefined" FILE * variable, declared in stdio.h.

    It is the "standard input", which is normally your "console" [e.g what you type on the keyboard]. Or if you use redirection such as "myprog < somefile" it can be a file as input.

    You should, in normal applications, never need to open or close stdin.

    There are also two standard output channels:
    stdout - normally your console, but is sometimes redirected to an output file, e.g. "myprog > somefile".
    stderr - a second channel that is normally connected to the console. This is meant to show error and information to the user. It is very rarely redirected, so if your application is writing on stdout that is redirected, messages to stderr will normally show up on the console anyways.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    84
    Thank you it make sense now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking stdin for input
    By hawaiian robots in forum C Programming
    Replies: 7
    Last Post: 05-19-2009, 09:06 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Replies: 2
    Last Post: 07-12-2008, 12:00 PM
  4. value of stdin (not zero?)
    By taisao in forum Linux Programming
    Replies: 3
    Last Post: 05-27-2007, 08:14 AM
  5. stdin question
    By oomen3 in forum C Programming
    Replies: 6
    Last Post: 02-19-2003, 02:52 PM