Standard Streams and Redirection

A C program has associated with it standard streams. You do not have to open these streams, because they are automatically set up for you by C when you include the stdio.h header file. Table 1 below shows three standard streams for C and the functions that implicitly use them.

Table 1. C Standard Streams
Name of stream Purpose Functions that use it
stdin The input device from which your C program usually retrieves its data. getchar() scanf() gets()
stdout The output device to which your C program normally directs its output. printf() puts() putchar()
stderr The output device to which your C program directs its diagnostic messages. LE/VSE C Run-Time uses stderr to collect error messages about exceptions that occur. perror()

On I/O operations requiring a file pointer, you can use stdin, stdout, or stderr in the same manner as you would any other file pointer.

The default behavior for the C standard streams is for them to open automatically on first reference. You do not have to call fopen() to open them. For example:
   printf("%d\n",n);
with no preceding fopen() statement writes the decimal number n to the stdout stream.

By default, stdin interprets the character sequence /* as indicating that the end of the file has been reached.