From WikiChip
Difference between revisions of "c/standard streams"
< c

(Created page with "The '''standard streams''' are three predefined streams between the program and the host environment open and available for use by every C program when the <code>main</code> f...")
 
m (corrected typo)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The '''standard streams''' are three predefined streams between the program and the host environment open and available for use by every C program when the <code>main</code> function of the program is invoked. The three standard streams are the '''standard input''', '''standard output''', and the '''standard error'''' streams.
+
{{c title|Standard Streams}}
 +
The '''standard streams''' are three predefined streams between the program and the host environment open and available for use by every C program when the <code>main</code> function of the program is invoked. The three standard streams are the '''standard input''', '''standard output''', and the '''standard error''' streams.
  
 
== <stdio.h> ==
 
== <stdio.h> ==
The [[stdio.h - C|<stdio.h>]] [[C standard library|standard header]] provides definitions for three external variables. The three predefined streams are:
+
The {{C|stdio.h|<stdio.h>}} {{C|standard library|standard header}} provides definitions for three external variables. The three predefined streams are:
 
<source lang="C">
 
<source lang="C">
 
#include <stdio.h>
 
#include <stdio.h>

Latest revision as of 06:28, 4 January 2015

The standard streams are three predefined streams between the program and the host environment open and available for use by every C program when the main function of the program is invoked. The three standard streams are the standard input, standard output, and the standard error streams.

<stdio.h>[edit]

The <stdio.h> standard header provides definitions for three external variables. The three predefined streams are:

#include <stdio.h>

extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;

stdin[edit]

The stdin extern variable which is of type FILE * is the standard input stream which is usually the normal source of input for the program such as the keyboard. On some environments, the host environment can also redirect files and other types of streams to the standard input.

stdout[edit]

The stdout extern variable which is of type FILE * is the standard output stream which is used for normal output from the program. Typically this stream is connected to a terminal.

stderr[edit]

The 'stderr extern variable which is of type FILE * is the standard error stream. This stream is used for error messages and reporting diagnostics issued by the program.