Search code examples
cprintfstdinstdio

Where to find `stdin` macro declaration?


My method suppose to switch text output between text file and stdin. So I been thinking about something like:

    void _connection(char mode) {   /* pass 'v' as an argument to set verbous mode*/
      FILE *stream
      
      if (mode == 'v')
        fopen(stream, "stdin location?");
      else
        fopen(stream, "../stream");

      fprintf(stream, "Connecting to the queue...");
      ...

Searching my system I been not able to find any stdin declaration. The stdio.h source file, on my system, is using this macro, but I can't get where it get it from. I mean, there is no inputs file or any macro called stdin in this file.


Solution

  • Find it here (Unix):

    /usr/include/stdio.h
    

    Or on Windows:

    (Compiler Path)\include\stdio.h
    

    Note that the ISO C standard requires stdin/stdout/stderr to be macros, while POSIX requires them to be external FILE* identifiers, so you may see this on POSIX-compliant systems (Linux and others):

    #define stdin stdin