stdin
, stdout
, and stderr
These are file descriptors, numbered as 0, 1, 2 respectively in linux. What we notmally think of as terminal input and output are stdin
and stdout
respectively.
In C, we represent files as pointers to memory, FILE *
. We have two functions very similar to printf
and scanf
, which are fprintf
and fscanf
respectively.
This allows us to read names from a file without the need for shell input/output redirection.
char line[100];
FILE* fpointer = fopen("/path/to/input/file", 'r'); /* open the file in read mode */