📄 all.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>Standard C I/O</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">Standard C I/O</a> </div> <div class="name-format"> clearerr </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> void clearerr( FILE *stream );</pre> <p>The clearerr function resets the error flags and <strong>EOF</strong> indicator for the given <em>stream</em>. When an error occurs, you can use <a href="perror.html">perror</a>() to figure out which error actually occurred.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="feof.html">feof</a><br> <a href="ferror.html">ferror</a><br> <a href="perror.html">perror</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> fclose </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> int fclose( FILE *stream ); </pre> <p>The function fclose() closes the given file stream, deallocating any buffers associated with that stream. fclose() returns 0 upon success, and <strong>EOF</strong> otherwise.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="fflush.html">fflush</a><br> <a href="fopen.html">fopen</a><br> <a href="freopen.html">freopen</a><br> <a href="setbuf.html">setbuf</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> feof </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> int feof( FILE *stream ); </pre> <p>The function feof() returns a nonzero value if the end of the given file <em>stream</em> has been reached.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="clearerr.html">clearerr</a><br> <a href="ferror.html">ferror</a><br> <a href="getc.html">getc</a><br> <a href="perror.html">perror</a><br> <a href="putc.html">putc</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> ferror </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> int ferror( FILE *stream );</pre> <p>The ferror() function looks for errors with <em>stream</em>, returning zero if no errors have occured, and non-zero if there is an error. In case of an error, use <a href="perror.html">perror</a>() to determine which error has occured.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="clearerr.html">clearerr</a><br> <a href="feof.html">feof</a><br> <a href="perror.html">perror</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> fflush </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> int fflush( FILE *stream );</pre> <p>If the given file <em>stream</em> is an output stream, then fflush() causes the output buffer to be written to the file. If the given <em>stream</em> is of the input type, then fflush() causes the input buffer to be cleared. fflush() is useful when debugging, if a program segfaults before it has a chance to write output to the screen. Calling fflush( <strong>stdout</strong> ) directly after debugging output will ensure that your output is displayed at the correct time.</p> <pre class="example-code"> printf( "Before first call\n" ); fflush( <strong>stdout</strong> ); shady_function(); printf( "Before second call\n" ); fflush( <strong>stdout</strong> ); dangerous_dereference(); </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="fclose.html">fclose</a><br> <a href="fopen.html">fopen</a><br> <a href="fread.html">fread</a><br> <a href="fwrite.html">fwrite</a><br> <a href="getc.html">getc</a><br> <a href="putc.html">putc</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> fgetc </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> int fgetc( FILE *stream );</pre> <p>The fgetc() function returns the next character from <em>stream</em>, or <strong>EOF</strong> if the end of file is reached or if there is an error.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="fopen.html">fopen</a><br> <a href="fputc.html">fputc</a><br> <a href="fread.html">fread</a><br> <a href="fwrite.html">fwrite</a><br> <a href="getc.html">getc</a><br> <a href="getchar.html">getchar</a><br> <a href="gets.html">gets</a><br> <a href="putc.html">putc</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> fgetpos </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> int fgetpos( FILE *stream, fpos_t *position );</pre> <p>The fgetpos() function stores the file position indicator of the given file <em>stream</em> in the given <em>position</em> variable. The position variable is of type fpos_t (which is defined in stdio.h) and is an object that can hold every possible position in a FILE. fgetpos() returns zero upon success, and a non-zero value upon failure.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="fseek.html">fseek</a><br> <a href="fsetpos.html">fsetpos</a><br> <a href="ftell.html">ftell</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> fgets </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> char *fgets( char *str, int num, FILE *stream );</pre> <p>The function fgets() reads up to <em>num</em> - 1 characters from the given file <em>stream</em> and dumps them into <em>str</em>. The string that fgets() produces is always <strong>NULL</strong>-terminated. fgets() will stop when it reaches the end of a line, in which case <em>str</em> will contain that newline character. Otherwise, fgets() will stop when it reaches <em>num</em> - 1 characters or encounters the <strong>EOF</strong> character. fgets() returns <em>str</em> on success, and <strong>NULL</strong> on an error.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="fputs.html">fputs</a><br> <a href="fscanf.html">fscanf</a><br> <a href="gets.html">gets</a><br> <a href="scanf.html">scanf</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> fopen </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> FILE *fopen( const char *fname, const char *mode );</pre> <p>The fopen() function opens a file indicated by <em>fname</em> and returns a stream associated with that file. If there is an error, fopen() returns <strong>NULL</strong>. <em>mode</em> is used to determine how the file will be treated (i.e. for input, output, etc)</p> <table class="code-table"> <tr> <th class="code-table-th">Mode</th> <th class="code-table-th">Meaning</th> </tr> <tr> <td class="code-table-td">"r"</td> <td class="code-table-td">Open a text file for reading</td> </tr> <tr> <td class="code-table-td">"w"</td> <td class="code-table-td">Create a text file for writing</td> </tr> <tr> <td class="code-table-td">"a"</td> <td class="code-table-td">Append to a text file</td> </tr> <tr> <td class="code-table-td">"rb"</td> <td class="code-table-td">Open a binary file for reading</td> </tr> <tr> <td class="code-table-td">"wb"</td> <td class="code-table-td">Create a binary file for writing</td> </tr> <tr> <td class="code-table-td">"ab"</td> <td class="code-table-td">Append to a binary file</td> </tr> <tr> <td class="code-table-td">"r+"</td> <td class="code-table-td">Open a text file for read/write</td> </tr> <tr> <td class="code-table-td">"w+"</td> <td class="code-table-td">Create a text file for read/write</td> </tr> <tr> <td class="code-table-td">"a+"</td> <td class="code-table-td">Open a text file for read/write</td> </tr> <tr> <td class="code-table-td">"rb+"</td> <td class="code-table-td">Open a binary file for read/write</td> </tr> <tr> <td class="code-table-td">"wb+"</td> <td class="code-table-td">Create a binary file for read/write</td> </tr> <tr> <td class="code-table-td">"ab+"</td> <td class="code-table-td">Open a binary file for read/write</td> </tr> </table> <p>An example:</p> <pre class="example-code"> int ch; FILE *input = fopen( "stuff", "r" ); ch = getc( input ); </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="fclose.html">fclose</a><br> <a href="fflush.html">fflush</a><br> <a href="fgetc.html">fgetc</a><br> <a href="fputc.html">fputc</a><br> <a href="fread.html">fread</a><br> <a href="freopen.html">freopen</a><br> <a href="fseek.html">fseek</a><br> <a href="fwrite.html">fwrite</a><br> <a href="getc.html">getc</a><br> <a href="getchar.html">getchar</a><br> <a href="setbuf.html">setbuf</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> fprintf </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdio.h> int fprintf( FILE *stream, const char *format, ... );</pre> <p>The fprintf() function sends information (the arguments) according to the specified <em>format</em> to the file indicated by <em>stream</em>. fprintf() works just like <a href= "printf.html">printf</a>() as far as the format goes. The return value of fprintf() is the number of characters outputted, or a negative number if an error occurs. An example:</p> <pre class="example-code"> char name[20] = "Mary"; FILE *out; out = fopen( "output.txt", "w" ); if( out != <strong>NULL</strong> ) fprintf( out, "Hello %s\n", name ); </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="fputc.html">fputc</a><br> <a href="fputs.html">fputs</a><br> <a href="fscanf.html">fscanf</a><br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -