⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stdio_details.html

📁 ssd5 数据结构的课件
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1st October 2002), see www.w3.org">    <title>Standard C I/O</title>  </head>  <body bgcolor="#ffffff">    <table width="100%" bgcolor="#eeeeff">      <tr>        <td><a href="index.html">cppreference.com</a> -&gt; <a href="stdio.html">Standard C I/O</a> -&gt;        Details</td>      </tr>    </table>    <h1>Standard C I/O</h1>    <hr>    <h2><a name="clearerr">clearerr</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  void clearerr( FILE *stream );</pre>        </td>      </tr>    </table>    <p>The clearerr function resets the error flags and EOF indicator for the given stream. When an error    occurs, you can use <a href="#perror">perror()</a> to figure out which error actually occurred.</p>    <i>Related topics:</i><br>     <strong><a href="#feof">feof()</a>, <a href="#ferror">ferror()</a>, and <a href=    "#perror">perror()</a>.</strong>     <hr>    <h2><a name="fclose">fclose</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fclose( FILE *stream );</pre>        </td>      </tr>    </table>    <p>The function fclose() closes the given file stream, deallocating any buffers associated with that    stream. fclose() returns 0 upon success, and EOF otherwise.</p>    <i>Related topics:</i><br>     <strong><a href="#fopen">fopen()</a>, <a href="#freopen">freopen()</a>, <a href=    "#fflush">fflush()</a></strong>     <hr>    <h2><a name="feof">feof</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int feof( FILE *stream );</pre>        </td>      </tr>    </table>    <p>The function feof() returns a nonzero value if the end of the given file stream has been reached.</p>    <i>Related topics:</i><br>     <strong><a href="#clearerr">clearerr()</a>, <a href="#ferror">ferror()</a>,      <a href="#perror">perror()</a>, <a href="#putc">putc()</a>, <a href="#getc">getc()</a></strong>     <hr>    <h2><a name="ferror">ferror</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int ferror( FILE *stream );</pre>        </td>      </tr>    </table>    <p>The ferror() function looks for errors with <i>stream</i>, returning zero if no errors have occured,    and non-zero if there is an error. In case of an error, use <a href="#perror">perror()</a> to determine    which error has occured.</p>    <i>Related topics:</i><br>    <strong><a href="#clearerr">clearerr()</a>, <a href="#feof">feof()</a>,     <a href="#perror">perror()</a></strong>     <hr>    <h2><a name="fflush">fflush</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fflush( FILE *stream );</pre>        </td>      </tr>    </table>    <p>If the given file stream is an output stream, then fflush() causes the output buffer to be written to    the file. If the given stream 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( STDOUT ) directly after debugging output will ensure that your output is    displayed at the correct time.</p><pre>    printf( "Before first call\n" );    fflush( STDOUT );    shady_function();    printf( "Before second call\n" );    fflush( STDOUT );    dangerous_dereference();</pre>    <i>Related topics:</i><br>     <strong><a href="#fclose">fclose()</a>, <a href="#fopen">fopen()</a>, <a href="#fread">fread()</a>, <a    href="#fwrite">fwrite()</a>, <a href="#getc">getc()</a>, <a href="#putc">putc()</a></strong>     <hr>    <h2><a name="fgetc">fgetc</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fgetc( FILE *stream );</pre>        </td>      </tr>    </table>    <p>The fgetc() function returns the next character from <i>stream</i>, or EOF if the end of file is    reached or if there is an error.</p>    <i>Related topics:</i><br>     <strong><a href="#fputc">fputc()</a>, <a href="#getc">getc()</a>, <a href="#putc">putc()</a>,      <a href="#fopen">fopen()</a></strong>     <hr>    <h2><a name="fgetpos">fgetpos</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fgetpos( FILE *stream, fpos_t *position );</pre>        </td>      </tr>    </table>    <p>The fgetpos() function stores the file position indicator of the given file stream in the given    position 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>    <i>Related topics:</i><br>     <strong><a href="#fsetpos">fsetpos()</a>, <a href="#fseek">fseek()</a>,      <a href="#ftell">ftell()</a></strong>     <hr>    <h2><a name="fgets">fgets</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  char *fgets( char *str, int num, FILE *stream );</pre>        </td>      </tr>    </table>    <p>The function fgets() reads up to <i>num - 1</i> characters from the given file stream and dumps them    into <i>str</i>. fgets() will stop when it reaches the end of a line, in which case <i>str</i> will be    terminated with a newline. If fgets() reaches <i>num - 1</i> characters or encounters the EOF, <i>str</i>    will be null-terminated. fgets() returns <i>str</i> on success, and NULL on an error.</p>    <hr>    <h2><a name="fopen">fopen</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  FILE *fopen( const char *fname, const char *mode );</pre>        </td>      </tr>    </table>    <p>The fopen() function opens a file indicated by <i>fname</i> and returns a stream associated with that    file. If there is an error, fopen() returns NULL. <i>mode</i> is used to determine how the file will be    treated (i.e. for input, output, etc)</p>    <table bgcolor="#eeeeff">      <tr>        <td><strong>Mode</strong></td>        <td><strong>Meaning</strong></td>      </tr>      <tr>        <td>"r"</td>        <td>Open a text file for reading</td>      </tr>      <tr>        <td>"w"</td>        <td>Create a text file for writing</td>      </tr>      <tr>        <td>"a"</td>        <td>Append to a text file</td>      </tr>      <tr>        <td>"rb"</td>        <td>Open a binary file for reading</td>      </tr>      <tr>        <td>"wb"</td>        <td>Create a binary file for writing</td>      </tr>      <tr>        <td>"ab"</td>        <td>Append to a binary file</td>      </tr>      <tr>        <td>"r+"</td>        <td>Open a text file for read/write</td>      </tr>      <tr>        <td>"w+"</td>        <td>Create a text file for read/write</td>      </tr>      <tr>        <td>"a+"</td>        <td>Open a text file for read/write</td>      </tr>      <tr>        <td>"rb+"</td>        <td>Open a binary file for read/write</td>      </tr>      <tr>        <td>"wb+"</td>        <td>Create a binary file for read/write</td>      </tr>      <tr>        <td>"ab+"</td>        <td>Open a binary file for read/write</td>      </tr>    </table>    <p>An example:</p><pre>    char ch;    FILE *input = fopen( "stuff", "r" );    ch = getc( input );    </pre>    <hr>    <h2><a name="fprintf">fprintf</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fprintf( FILE *stream, const char *format, ... );</pre>        </td>      </tr>    </table>    <p>The fprintf() function sends information (the arguments) according to the specified <i>format</i> to    the file indicated by <i>stream</i>. fprintf() works just like <a href="#printf">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>    char name[20] = "Mary";    FILE *out;    out = fopen( "output.txt", "w" );    if( out != NULL )      fprintf( out, "Hello %s\n", name );</pre>    <i>Related topics:</i><br>     <strong><a href="#printf">printf()</a>, <a href="#fscanf">fscanf()</a></strong>     <hr>    <h2><a name="fputc">fputc</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fputc( int ch, FILE *stream );</pre>        </td>      </tr>    </table>    <p>The function fputc() writes the given character <i>ch</i> to the given output stream. The return value    is the character, unless there is an error, in which case the return value is EOF.</p>    <i>Related topics:</i><br>     <strong><a href="#fgetc">fgetc()</a>, <a href="#fopen">fopen()</a>, <a href="#fprintf">fprintf()</a>,      <a href="#fread">fread()</a>, <a href="#fwrite">fwrite()</a></strong>     <hr>    <h2><a name="fputs">fputs</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fputs( const char *str, FILE *stream );</pre>        </td>      </tr>    </table>    <p>The fputs() function writes an array of characters pointed to by <i>str</i> to the given output    stream. The return value is non-negative on success, and EOF on failure.</p>    <i>Related topics:</i><br>     <strong><a href="#fgets">fgets()</a>, <a href="#gets">gets()</a>, <a href="#puts">puts()</a>,      <a href="#fprintf">fprintf()</a>, <a href="#fscanf">fscanf()</a></strong>     <hr>    <h2><a name="fread">fread</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fread( void *buffer, size_t size, size_t num, FILE *stream );</pre>        </td>      </tr>    </table>    <p>The function fread() reads <i>num</i> number of objects (where each object is <i>size</i> bytes) and    places them into the array pointed to by <i>buffer</i>. The data comes from the given input stream. The    return value of the function is the number of things read...use <a href="#feof">feof()</a> or <a href=    "#ferror">ferror()</a> to figure out if an error occurs.</p>    <i>Related topics:</i><br>     <strong><a href="#fwrite">fwrite()</a>, <a href="#fopen">fopen()</a>, <a href="#fscanf">fscanf()</a>,      <a href="#fgetc">fgetc()</a>, <a href="#getc">getc()</a></strong>     <hr>    <h2><a name="freopen">freopen</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  FILE *freopen( const char *fname, const char *mode, FILE *stream );</pre>        </td>      </tr>    </table>    <p>The freopen() function is used to reassign an existing stream to a different file and mode. After a    call to this function, the given file stream will refer to <i>fname</i> with access given by <i>mode</i>.    The return value of freopen() is the new stream, or NULL if there is an error.</p>    <i>Related topics:</i><br>     <strong><a href="#fopen">fopen()</a>, <a href="#fclose">fclose()</a></strong>     <hr>    <h2><a name="fscanf">fscanf</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -