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