1STDIO(3)                   Linux Programmer's Manual                  STDIO(3)
2
3
4

NAME

6       stdio - standard input/output library functions
7

SYNOPSIS

9       #include <stdio.h>
10
11       FILE *stdin;
12       FILE *stdout;
13       FILE *stderr;
14

DESCRIPTION

16       The  standard  I/O  library  provides  a  simple and efficient buffered
17       stream I/O interface.  Input and output is  mapped  into  logical  data
18       streams  and the physical I/O characteristics are concealed.  The func‐
19       tions and macros are listed below; more information is  available  from
20       the individual man pages.
21
22       A  stream  is associated with an external file (which may be a physical
23       device) by opening a file, which may involve creating a new file.  Cre‐
24       ating  an existing file causes its former contents to be discarded.  If
25       a file can support positioning  requests  (such  as  a  disk  file,  as
26       opposed  to a terminal), then a file position indicator associated with
27       the stream is positioned at the start of the file (byte  zero),  unless
28       the  file  is  opened  with append mode.  If append mode is used, it is
29       unspecified whether the position indicator will be placed at the  start
30       or the end of the file.  The position indicator is maintained by subse‐
31       quent reads, writes and positioning requests.  All input occurs  as  if
32       the  characters were read by successive calls to the fgetc(3) function;
33       all output takes place as if all characters were written by  successive
34       calls to the fputc(3) function.
35
36       A  file  is  disassociated  from  a stream by closing the file.  Output
37       streams are flushed (any unwritten buffer contents are  transferred  to
38       the host environment) before the stream is disassociated from the file.
39       The value of a pointer to a FILE object is indeterminate after  a  file
40       is closed (garbage).
41
42       A  file  may  be  subsequently reopened, by the same or another program
43       execution, and its contents reclaimed or modified (if it can be reposi‐
44       tioned  at  the  start).   If the main function returns to its original
45       caller, or the exit(3) function is called, all open  files  are  closed
46       (hence  all  output  streams  are  flushed) before program termination.
47       Other methods of program termination, such as abort(3)  do  not  bother
48       about closing files properly.
49
50       At  program  startup, three text streams are predefined and need not be
51       opened explicitly: standard input  (for  reading  conventional  input),
52       standard  output  (for writing conventional output), and standard error
53       (for writing diagnostic output).  These streams are abbreviated  stdin,
54       stdout,  and  stderr.   When  opened,  the standard error stream is not
55       fully buffered;  the  standard  input  and  output  streams  are  fully
56       buffered  if  and  only  if  the streams do not refer to an interactive
57       device.
58
59       Output streams that refer to terminal devices are always line  buffered
60       by  default;  pending  output  to such streams is written automatically
61       whenever an input stream that refers to a terminal device is read.   In
62       cases  where  a large amount of computation is done after printing part
63       of a line on an output terminal, it is necessary to fflush(3) the stan‐
64       dard  output  before  going  off  and computing so that the output will
65       appear.
66
67       The stdio library is a part of the library libc and routines are  auto‐
68       matically loaded as needed by cc(1).  The SYNOPSIS sections of the fol‐
69       lowing manual pages indicate which include files are to be  used,  what
70       the compiler declaration for the function looks like and which external
71       variables are of interest.
72
73       The following are defined as macros; these  names  may  not  be  reused
74       without  first  removing their current definitions with #undef: BUFSIZ,
75       EOF, FILENAME_MAX, FOPEN_MAX,  L_cuserid,  L_ctermid,  L_tmpnam,  NULL,
76       SEEK_END,  SEEK_SET, SEEK_CUR, TMP_MAX, clearerr, feof, ferror, fileno,
77       getc, getchar, putc, putchar, stderr, stdin, stdout.  Function versions
78       of  the  macro functions feof, ferror, clearerr, fileno, getc, getchar,
79       putc, and putchar exist and will be used if the macros definitions  are
80       explicitly removed.
81
82   List of functions
83       Function         Description
84       ──────────────────────────────────────────────────────────────────────
85       clearerr(3)      check and reset stream status
86       fclose(3)        close a stream
87       fdopen(3)        stream open functions
88       feof(3)          check and reset stream status
89       ferror(3)        check and reset stream status
90       fflush(3)        flush a stream
91       fgetc(3)         get next character or word from input stream
92       fgetpos(3)       reposition a stream
93       fgets(3)         get a line from a stream
94       fileno(3)        return the integer descriptor of the argument stream
95       fopen(3)         stream open functions
96       fprintf(3)       formatted output conversion
97       fpurge(3)        flush a stream
98       fputc(3)         output a character or word to a stream
99       fputs(3)         output a line to a stream
100       fread(3)         binary stream input/output
101       freopen(3)       stream open functions
102       fscanf(3)        input format conversion
103       fseek(3)         reposition a stream
104       fsetpos(3)       reposition a stream
105       ftell(3)         reposition a stream
106       fwrite(3)        binary stream input/output
107       getc(3)          get next character or word from input stream
108       getchar(3)       get next character or word from input stream
109       gets(3)          get a line from a stream
110       getw(3)          get next character or word from input stream
111       mktemp(3)        make temporary filename (unique)
112       perror(3)        system error messages
113       printf(3)        formatted output conversion
114       putc(3)          output a character or word to a stream
115       putchar(3)       output a character or word to a stream
116       puts(3)          output a line to a stream
117       putw(3)          output a character or word to a stream
118       remove(3)        remove directory entry
119       rewind(3)        reposition a stream
120       scanf(3)         input format conversion
121       setbuf(3)        stream buffering operations
122       setbuffer(3)     stream buffering operations
123       setlinebuf(3)    stream buffering operations
124       setvbuf(3)       stream buffering operations
125       sprintf(3)       formatted output conversion
126       sscanf(3)        input format conversion
127       strerror(3)      system error messages
128       sys_errlist(3)   system error messages
129       sys_nerr(3)      system error messages
130       tempnam(3)       temporary file routines
131       tmpfile(3)       temporary file routines
132
133       tmpnam(3)        temporary file routines
134       ungetc(3)        un-get character from input stream
135       vfprintf(3)      formatted output conversion
136       vfscanf(3)       input format conversion
137       vprintf(3)       formatted output conversion
138       vscanf(3)        input format conversion
139       vsprintf(3)      formatted output conversion
140       vsscanf(3)       input format conversion
141

CONFORMING TO

143       The stdio library conforms to C89.
144

SEE ALSO

146       close(2), open(2), read(2), write(2), stdout(3), unlocked_stdio(3)
147

COLOPHON

149       This  page  is  part of release 5.02 of the Linux man-pages project.  A
150       description of the project, information about reporting bugs,  and  the
151       latest     version     of     this    page,    can    be    found    at
152       https://www.kernel.org/doc/man-pages/.
153
154
155
156                                  2017-11-26                          STDIO(3)
Impressum