CS0.101 - Computer Programming | C Pro Lecture 31

with Prof. Suresh Purini
Nov 24, 2020 - Tuesday
Written by: Pratyaksh Gautam

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.

Files and file pointers

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 */

Commandline arguments