What's the int macro for stdin?
Asked Answered
F

4

21

stdin is of type FILE *,

is there a fd macro for it?

Or do I need to convert it myself?

Fragile answered 5/7, 2011 at 13:30 Comment(2)
You could just "guess" that stdin <==> 0; stdout <==> 1; stderr <==> 2Bathypelagic
There's no need to guess - POSIX requires that, so you could legitimately just use the numbers.Sneaky
C
37

STDIN_FILENO from unistd.h

Cheryllches answered 5/7, 2011 at 13:32 Comment(0)
S
7

fileno(stdin)

Sinistrocular answered 5/7, 2011 at 13:31 Comment(0)
A
2

The following are the integer file descriptors for the standard streams:

  • 0: stdin
  • 1: stdout
  • 2: stderr
Auklet answered 5/7, 2011 at 13:32 Comment(0)
E
1
#include<unistd.h>
#include<stdlib.h>
int main(){
    
    char ch;
    read(STDIN_FILENO,&ch,1);
    write(STDOUT_FILENO,&ch,1);

    exit(EXIT_SUCCESS);
}
Eck answered 27/8, 2023 at 10:23 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.