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

📄 stdio_details.html

📁 ssd5 数据结构的课件
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<pre>  #include &lt;stdio.h&gt;  int fscanf( FILE *stream, const char *format, ... );</pre>        </td>      </tr>    </table>    <p>The function fscanf() reads data from the given file stream in a manner exactly like <a href=    "#scanf">scanf()</a>. The return value of fscanf() is the number of variables that are actually assigned    values, or EOF if no assignments could be made.</p>    <i>Related topics:</i><br>     <strong><a href="#scanf">scanf()</a>, <a href="#fprintf">fprintf()</a></strong>     <hr>    <h2><a name="fseek">fseek</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fseek( FILE *stream, long offset, int origin );</pre>        </td>      </tr>    </table>    <p>The function fseek() sets the file position data for the given stream. The <i>origin</i> value should    have one of the following values (defined in stdio.h):</p>    <table bgcolor="#eeeeff">      <tr>        <td><strong>Name</strong></td>        <td><strong>Explanation</strong></td>      </tr>      <tr>        <td>SEEK_SET</td>        <td>Seek from the start of the file</td>      </tr>      <tr>        <td>SEEK_CUR</td>        <td>Seek from the current location</td>      </tr>      <tr>        <td>SEEK_END</td>        <td>Seek from the end of the file</td>      </tr>    </table>    <p>fseek() returns zero upon success, non-zero on failure. You can use fseek() to move beyond a file, but    not before the beginning. Using fseek() clears the EOF flag associated with that stream.</p>    <i>Related topics:</i><br>     <strong><a href="#ftell">ftell()</a>, <a href="#rewind">rewind()</a>, <a href="#fopen">fopen()</a>,      <a href="#fgetpos">fgetpos()</a>, <a href="#fsetpos">fsetpos()</a></strong>     <hr>    <h2><a name="fsetpos">fsetpos</a></h2>    <i>Syntax:</i>    <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fsetpos( FILE *stream, const fpos_t *position );</pre>        </td>      </tr>    </table>    <p>The fsetpos() function moves the file position indicator for the given stream to a location specified    by the <i>position</i> object. fpos_t is defined in stdio.h. The return value for fsetpos() is zero upon    success, non-zero on failure.</p>    <i>Related topics:</i><br>     <strong><a href="#fgetpos">fgetpos()</a>, <a href="#fseek">fseek()</a>,      <a href="#ftell">ftell()</a></strong>     <hr>    <h2><a name="ftell">ftell</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  long ftell( FILE *stream );</pre>        </td>      </tr>    </table>    <p>The ftell() function returns the current file position for <i>stream</i>, or -1 if an error    occurs.</p>    <i>Related topics:</i><br>     <strong><a href="#fseek">fseek()</a>, <a href="#fgetpos">fgetpos()</a></strong>     <hr>    <h2><a name="fwrite">fwrite</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int fwrite( const void *buffer, size_t size, size_t count, FILE *stream );</pre>        </td>      </tr>    </table>    <p>The fwrite() function writes, from the array <i>buffer</i>, <i>count</i> objects of size <i>size</i>    to <i>stream</i>. The return value is the number of objects written.</p>    <i>Related topics:</i><br>     <strong><a href="#fread">fread()</a>, <a href="#fscanf">fscanf()</a>, <a href="#getc">getc()</a>,      <a href="#fgetc">fgetc()</a></strong>     <hr>    <h2><a name="getc">getc</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int getc( FILE *stream );</pre>        </td>      </tr>    </table>    <p>The getc() function returns the next character from <i>stream</i>, or EOF if the end of file is    reached. getc() is identical to fgetc(). For example:</p><pre>    char ch;    FILE *input = fopen( "stuff", "r" );        ch = getc( input );    while( ch != EOF ) {      printf( "%c", ch );      ch = getc( input );    }</pre>    <i>Related topics:</i><br>     <strong><a href="#fputc">fputc()</a>, <a href="#fgetc">fgetc()</a>, <a href="#putc">putc()</a>,      <a href="#fopen">fopen()</a></strong>     <hr>    <h2><a name="getchar">getchar</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int getchar( void );</pre>        </td>      </tr>    </table>    <p>The getchar() function returns the next character from STDIN, or EOF if the end of file is    reached.</p>    <i>Related topics:</i><br>     <strong><a href="#fputc">fputc()</a>, <a href="#fgetc">fgetc()</a>, <a href="#putc">putc()</a>,      <a href="#fopen">fopen()</a></strong>     <hr>    <h2><a name="gets">gets</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  char *gets( char *str );</pre>        </td>      </tr>    </table>    <p>The gets() function reads characters from STDIN and loads them into <i>str</i>, until a newline or EOF    is reached. The newline character is translated into a null termination. The return value of gets() is    the read-in string, or NULL if there is an error.</p>    <i>Related topics:</i><br>     <strong><a href="#fputs">fputs()</a>, <a href="#fgetc">fgetc()</a>, <a href="#fgets">fgets()</a>,      <a href="#puts">puts()</a></strong>     <hr>    <h2><a name="perror">perror</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  void perror( const char *str );</pre>        </td>      </tr>    </table>    <p>The perror() function prints <i>str</i> and an implementation-defined error message corresponding to    the global variable <strong>errno</strong>.</p>    <hr>    <h2><a name="printf">printf</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int printf( const char *format, ... );</pre>        </td>      </tr>    </table>    <p>The printf() function prints output to STDOUT, according to <i>format</i> and other arguments passed    to printf(). The string <i>format</i> consists of two types of items - characters that will be printed to    the screen, and format commands that define how the other arguments to printf() are displayed. Basically,    you specify a <i>format</i> string that has text in it, as well as "special" characters that map to the    other arguments of printf(). For example, this code</p><pre>    char name[20] = "Bob";    int age = 21;    printf( "Hello %s, you are %d years old\n", name, age );</pre>    <p>displays the following output:</p><pre>    Hello Bob, you are 21 years old</pre>    <p>The %s means, "insert the first argument, a string, right here." The %d indicates that the second    argument (an integer) should be placed there. There are different %-codes for different variable types,    as well as options to limit the length of the variables and whatnot.</p>    <table bgcolor="#eeeeff">      <tr>        <td><strong>Code</strong></td>        <td><strong>Format</strong></td>      </tr>      <tr>        <td>%c</td>        <td>character</td>      </tr>      <tr>        <td>%d</td>        <td>signed integers</td>      </tr>      <tr>        <td>%i</td>        <td>signed integers</td>      </tr>      <tr>        <td>%e</td>        <td>scientific notation, with a lowercase "e"</td>      </tr>      <tr>        <td>%E</td>        <td>scientific notation, with a uppercase "E"</td>      </tr>      <tr>        <td>%f</td>        <td>floating point</td>      </tr>      <tr>        <td>%g</td>        <td>use %e or %f, whichever is shorter</td>      </tr>      <tr>        <td>%G</td>        <td>use %E or %f, whichever is shorter</td>      </tr>      <tr>        <td>%o</td>        <td>octal</td>      </tr>      <tr>        <td>%s</td>        <td>a string of characters</td>      </tr>      <tr>        <td>%u</td>        <td>unsigned integer</td>      </tr>      <tr>        <td>%x</td>        <td>unsigned hexadecimal, with lowercase letters</td>      </tr>      <tr>        <td>%X</td>        <td>unsigned hexadecimal, with uppercase letters</td>      </tr>      <tr>        <td>%p</td>        <td>a pointer</td>      </tr>      <tr>        <td>%n</td>        <td>the argument shall be a pointer to an integer<br>         into which is placed the number of characters<br>         written so far</td>      </tr>      <tr>        <td>%%</td>        <td>a '%' sign</td>      </tr>    </table>    <p>An integer placed between a % sign and the format command acts as a minimum field width specifier, and    pads the output with spaces or zeros to make it long enough. If you want to pad with zeros, place a zero    before the minimum field width specifier. You can use a precision modifier, which has different meanings    depending on the format code being used.</p>    <ul>      <li>        With %e, %E, and %f, the precision modifier lets you specify the number of decimal places desired.        For example, <br>        <br>         <pre>    %12.6f</pre>        <p>will display a floating number at least 12 digits wide, with six decimal places.</p>      </li>      <li>With %g and %G, the precision modifier determines the maximum number of significant digits      displayed.</li>      <li>With %s, the precision modifer simply acts as a <strong>maximum</strong>field length, to complement      the minimum field length that precedes the period.</li>    </ul>    All of printf()'s output is right-justified, unless you place a minus sign right after the % sign. For    example, <br>    <br>     <pre>    %-12.4f</pre>    <p>will display a floating point number with a minimum of 12 characters, 4 decimal places, and left    justified. You may modify the %d, %i, %o, %u, and %x type specifiers with the letter <strong>l</strong>    and the letter <strong>h</strong> to specify long and short data types (e.g. %hd means a short integer).    The %e, %f, and %g type specifiers can have the letter <strong>l</strong> before them to indicate that a    double follows. The %g, %f, and %e type specifiers can be preceded with the character '#' to ensure that    the decimal point will be present, even if there are no decimal digits. The use of the '#' character with    the %x type specifier indicates that the hexidecimal number should be printed with the '0x' prefix. The    use of the '#' character with the %o type specifier indicates that the octal value should be displayed    with a 0 prefix.</p>    <p>You can also include <a href="escape_sequences.html">constant escape sequences</a> in the output    string.</p>    <p>The return value of printf() is the number of characters printed, or a negative number if an error    occurred.</p>    <i>Related topics:</i><br>     <strong><a href="#scanf">scanf()</a>, <a href="#fprintf">fprintf()</a></strong>     <hr>    <h2><a name="putc">putc</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdio.h&gt;  int putc( int ch, FILE *stream );</pre>        </td>      </tr>    </table>    <p>The putc() function writes the character <i>ch</i> to <i>stream</i>. The return value is the character    written, or EOF if there is an error. For example:</p><pre>    char ch;    FILE *input, *output;    input = fopen( "tmp.c", "r" );    output = fopen( "tmpCopy.c", "w" );    ch = getc( input );    while( ch != EOF ) {      putc( ch, output );      ch = getc( input );

⌨️ 快捷键说明

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