Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C file input/output
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Functions=== Most of the C file input/output functions are defined in {{mono|<stdio.h>}} (or in the [[C++]] header {{mono|cstdio}}, which contains the standard C functionality but in the {{mono|std}} [[namespace]]). {| class="wikitable" |- ! ! Byte<br />character ! Wide<br />character ! Description |- ! rowspan=9 | File access | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fopen}}[https://en.cppreference.com/w/c/io/fopen fopen] | Opens a file (with a non-Unicode filename on Windows and possible UTF-8 filename on Linux) |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|popen}}[https://man7.org/linux/man-pages/man3/popen.3.html popen] | opens a process by creating a pipe, forking, and invoking the shell |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|freopen}}[https://en.cppreference.com/w/c/io/freopen freopen] | Opens a different file with an existing stream |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fflush}}[https://en.cppreference.com/w/c/io/fflush fflush] | Synchronizes an output stream with the actual file |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fclose}}[https://en.cppreference.com/w/c/io/fclose fclose] | Closes a file |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|pclose}}[https://man7.org/linux/man-pages/man3/pclose.3p.html pclose] | closes a stream |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|setbuf}}[https://en.cppreference.com/w/c/io/setbuf setbuf] | Sets the buffer for a file stream |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|setvbuf}}[https://en.cppreference.com/w/c/io/setvbuf setvbuf] | Sets the buffer and its size for a file stream |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fwide}}[https://en.cppreference.com/w/c/io/fwide fwide] | Switches a file stream between wide-character I/O and narrow-character I/O |- ! rowspan=2 | Direct <br /> input/output | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fread}}[https://en.cppreference.com/w/c/io/fread fread] | Reads from a file |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fwrite}}[https://en.cppreference.com/w/c/io/fwrite fwrite] | Writes to a file |- ! rowspan=9 | Unformatted <br /> input/output | style="font-family:monospace" | {{anchor|fgetc|getc}}[https://en.cppreference.com/w/c/io/fgetc fgetc]<br />[https://en.cppreference.com/w/c/io/getc getc] | style="font-family:monospace"| {{anchor|fgetwc|getwc}}[https://en.cppreference.com/w/c/io/fgetwc fgetwc]<br />[https://en.cppreference.com/w/c/io/getwc getwc] | Reads a byte/{{mono|wchar_t}} from a file stream |- | style="font-family:monospace" | {{anchor|fgets}}[https://en.cppreference.com/w/c/io/fgets fgets] | style="font-family:monospace" | {{anchor|fgetws}}[https://en.cppreference.com/w/c/io/fgetws fgetws] | Reads a byte/{{mono|wchar_t}} line from a file stream |- | style="font-family:monospace" | {{anchor|fputc|putc}}[https://en.cppreference.com/w/c/io/fputc fputc]<br />[https://en.cppreference.com/w/c/io/putc putc] | style="font-family:monospace" | {{anchor|fputwc|putwc}}[https://en.cppreference.com/w/c/io/fputwc fputwc]<br />[https://en.cppreference.com/w/c/io/putwc putwc] | Writes a byte/{{mono|wchar_t}} to a file stream |- | style="font-family:monospace" | {{anchor|fputs}}[https://en.cppreference.com/w/c/io/fputs fputs] | style="font-family:monospace" | {{anchor|fputws}}[https://en.cppreference.com/w/c/io/fputws fputws] | Writes a byte/{{mono|wchar_t}} string to a file stream |- | style="font-family:monospace" | {{anchor|getchar}}[https://en.cppreference.com/w/c/io/getchar getchar] | style="font-family:monospace" | {{anchor|getwchar}}[https://en.cppreference.com/w/c/io/getwchar getwchar] | Reads a byte/{{mono|wchar_t}} from stdin |- | style="font-family:monospace" | {{anchor|gets}}<s>[https://en.cppreference.com/w/c/io/gets gets]</s> | {{n/a}} | Reads a byte string from stdin until a newline or end of file is encountered (deprecated in C99, removed from C11) |- | style="font-family:monospace" | {{anchor|putchar}}[https://en.cppreference.com/w/c/io/putchar putchar] | style="font-family:monospace" | {{anchor|putwchar}}[https://en.cppreference.com/w/c/io/putwchar putwchar] | Writes a byte/{{mono|wchar_t}} to stdout |- | style="font-family:monospace" | {{anchor|puts}}[https://en.cppreference.com/w/c/io/puts puts] | {{n/a}} | Writes a byte string to stdout |- | style="font-family:monospace" | {{anchor|ungetc}}[https://en.cppreference.com/w/c/io/ungetc ungetc] | style="font-family:monospace" | {{anchor|ungetwc}}[https://en.cppreference.com/w/c/io/ungetwc ungetwc] | Puts a byte/{{mono|wchar_t}} back into a file stream |- ! rowspan=5 | Formatted <br /> input/output | style="font-family:monospace" | {{anchor|scanf|fscanf|sscanf}}[https://en.cppreference.com/w/c/io/scanf scanf]<br />[https://en.cppreference.com/w/c/io/fscanf fscanf]<br />[https://en.cppreference.com/w/c/io/sscanf sscanf] | style="font-family:monospace" | {{anchor|wscanf|fwscanf|swscanf}}[https://en.cppreference.com/w/c/io/wscanf wscanf]<br />[https://en.cppreference.com/w/c/io/fwscanf fwscanf]<br />[https://en.cppreference.com/w/c/io/swscanf swscanf] | Reads formatted byte/{{mono|wchar_t}} input from stdin,<br />a file stream or a buffer |- | style="font-family:monospace" | {{anchor|vscanf|vfscanf|vsscanf}}[https://en.cppreference.com/w/c/io/vscanf vscanf]<br />[https://en.cppreference.com/w/c/io/vfscanf vfscanf]<br />[https://en.cppreference.com/w/c/io/vsscanf vsscanf] | style="font-family:monospace" | {{anchor|vwscanf|vfwscanf|vswscanf}}[https://en.cppreference.com/w/c/io/vwscanf vwscanf]<br />[https://en.cppreference.com/w/c/io/vfwscanf vfwscanf]<br />[https://en.cppreference.com/w/c/io/vswscanf vswscanf] | Reads formatted input byte/{{mono|wchar_t}} from stdin,<br />a file stream or a buffer using variable argument list |- | style="font-family:monospace" | {{anchor|printf|fprintf|sprintf|snprintf}}[https://en.cppreference.com/w/c/io/printf printf]<br />[https://en.cppreference.com/w/c/io/fprintf fprintf]<br />[https://en.cppreference.com/w/c/io/sprintf sprintf]<br />[https://en.cppreference.com/w/c/io/snprintf snprintf] | style="font-family:monospace" | {{anchor|wprintf|fwprintf|swprintf}}[https://en.cppreference.com/w/c/io/wprintf wprintf]<br />[https://en.cppreference.com/w/c/io/fwprintf fwprintf]<br />[https://en.cppreference.com/w/c/io/swprintf swprintf] | Prints formatted byte/{{mono|wchar_t}} output to stdout,<br />a file stream or a buffer |- | style="font-family:monospace" | {{anchor|vprintf|vfprintf|vsprintf|vsnprintf}}[https://en.cppreference.com/w/c/io/vprintf vprintf]<br />[https://en.cppreference.com/w/c/io/vfprintf vfprintf]<br />[https://en.cppreference.com/w/c/io/vsprintf vsprintf]<br />[https://en.cppreference.com/w/c/io/vsnprintf vsnprintf] | style="font-family:monospace" | {{anchor|vwprintf|vfwprintf|vswprintf}}[https://en.cppreference.com/w/c/io/vwprintf vwprintf]<br />[https://en.cppreference.com/w/c/io/vfwprintf vfwprintf]<br />[https://en.cppreference.com/w/c/io/vfwprintf vswprintf] | Prints formatted byte/{{mono|wchar_t}} output to stdout,<br />a file stream, or a buffer using variable argument list |- | style="font-family:monospace" | {{anchor|perror}}[https://en.cppreference.com/w/c/io/perror perror] | {{n/a}} | Writes a description of the [[errno.h|current error]] to stderr |- ! rowspan=5 | File positioning | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|ftell}}[https://en.cppreference.com/w/c/io/ftell ftell]<br/>ftello | Returns the current file position indicator |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fseek}}[https://en.cppreference.com/w/c/io/fseek fseek]<br/>fseeko | Moves the file position indicator to a specific location in a file |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fgetpos}}[https://en.cppreference.com/w/c/io/fgetpos fgetpos] | Gets the file position indicator |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fsetpos}}[https://en.cppreference.com/w/c/io/fsetpos fsetpos] | Moves the file position indicator to a specific location in a file |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|rewind}}[https://en.cppreference.com/w/c/io/rewind rewind] | Moves the file position indicator to the beginning in a file |- ! rowspan=3 | Error<br />handling | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|clearerr}}[https://en.cppreference.com/w/c/io/clearerr clearerr] | Clears errors |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|feof}}[https://en.cppreference.com/w/c/io/feof feof] | Checks for the end-of-file |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|ferror}}[https://en.cppreference.com/w/c/io/ferror ferror] | Checks for a file error |- ! rowspan=4 | Operations <br />on files | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|remove}}[https://en.cppreference.com/w/c/io/remove remove] | Erases a file |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|rename}}[https://en.cppreference.com/w/c/io/rename rename] | [[rename (computing)|Rename]]s a file |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|tmpfile}}[https://en.cppreference.com/w/c/io/tmpfile tmpfile] | Returns a pointer to a temporary file |- | colspan=2 style="text-align:center;font-family:monospace" | {{anchor|tmpnam}}[https://en.cppreference.com/w/c/io/tmpnam tmpnam] | Returns a unique filename |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)