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

📄 fscanf.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>fscanf</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_005_266">&nbsp;</a>NAME</h4><blockquote>fscanf, scanf, sscanf  - convert formatted input</blockquote><h4><a name = "tag_000_005_267">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>#include &lt;<a href="stdio.h.html">stdio.h</a>&gt;int fscanf(FILE *<i>stream</i>, const char *<i>format</i>, ... );int scanf(const char *<i>format</i>, ... );int sscanf(const char *<i>s</i>, const char *<i>format</i>, ... );</code></pre></blockquote><h4><a name = "tag_000_005_268">&nbsp;</a>DESCRIPTION</h4><blockquote>The<i>fscanf()</i>function reads from the named input<i>stream</i>.The<i>scanf()</i>function reads from the standard input stream<i><a href="stdin.html">stdin</a></i>.The<i>sscanf()</i>function reads from the string<i>s</i>.Each function reads bytes, interpretsthem according to a format, and stores the results in its arguments.Each expects, as arguments, a control string<i>format</i>described below, and a set of<i>pointer</i>argumentsindicating where the converted input should be stored.The result is undefined if there are insufficient arguments forthe format.If the format is exhausted while arguments remain, the excess argumentsare evaluated but are otherwise ignored.<p>Conversions can be applied to the<i>nth</i>argument after the<i>format</i>in the argument list, rather than to the next unused argument.In this case, the conversion character % (see below) is replacedby the sequence %<i>n</i>$, where <i>n</i> is a decimal integerin the range [1,&nbsp;{NL_ARGMAX}].This feature provides for the definition of format strings thatselect arguments in an order appropriate to specific languages.In format stringscontaining the %<i>n</i>$ form of conversion specifications,it is unspecified whether numberedarguments in the argument list can be referenced from the format stringmore than once.<p>The<i>format</i>can contain either form of a conversion specification, that is, %or %<i>n</i>$, but the two forms cannot normally be mixed within a single<i>format</i>string.The only exception to this is that %% or %* can be mixed with the%<i>n</i>$ form.<p>The<i>fscanf()</i>function in all its forms allows for detection of a language-dependent radixcharacter in the input string.  The radix character is definedin the program's locale (category LC_NUMERIC).In the POSIX locale, or in a locale wherethe radix character is not defined,the radix character defaults to a period (.).<p>The format is a character string, beginning and ending in itsinitial shift state, if any, composed of zero or more directives.Each directive is composed of one of the following:one or more white-space characters (space, tab, newline, vertical-tabor form-feed characters); an ordinary character (neither % nor awhite-space character);or a conversion specification.Each conversion specification is introduced by the character %or the character sequence<i>%n$</i>after which the following appear in sequence:<ul><p><li>An optional assignment-suppressing character *.<p><li>An optional non-zero decimal integer that specifies the maximum fieldwidth.<p><li>An optional size modifier h, l (ell) or Lindicating the size of the receiving object.The conversion characters d, i and n must be preceded by hif the corresponding argument is a pointer to<b>short int</b>rather than a pointer to<b>int</b>,or by l (ell) if it is a pointer to<b>long int</b>.Similarly, the conversion characters o, u and x must be preceded by hif the corresponding argument is a pointer to<b>unsigned short int</b>rather than a pointer to<b>unsigned int</b>,or by l (ell) if it is a pointer to<b>unsigned long int</b>.The conversion characters e, f and g must be preceded by l (ell)if the corresponding argument is a pointer to<b>double</b>rather than a pointer to<b>float</b>,or by L if it is a pointer to<b>long double</b>.Finally, the conversion characters c, s and [ must be precede by l(ell) if the corresponding argument is a pointer to<b>wchar_t</b>rather than a pointer to a character type.If an h, l (ell) or Lappears with any other conversion character, the behaviour is undefined.<p><li>A conversion characterthat specifies the type of conversion to be applied.The valid conversion characters are described below.<p></ul><p>The<i>fscanf()</i>functions execute each directive of the format in turn.  If a directive fails,as detailed below, the function returns.  Failures are described as inputfailures (due to the unavailability of input bytes) or matching failures (dueto inappropriate input).<p>A directive composed of one or more white-space characters isexecuted by reading input until no more valid input can be read, orup to the first byte which is not a white-space characterwhich remains unread.<p>A directive that is an ordinary character is executed asfollows.The next byte is read from the input and compared with thebyte that comprises the directive;if the comparison shows that they are not equivalent,the directive fails, and the differing and subsequentbytes remain unread.<p>A directive that is a conversion specification defines a set ofmatching input sequences, as described below for each conversion character.A conversion specification is executed in the following steps:<p>Input white-space characters (as specified by<i><a href="isspace.html">isspace()</a></i>)are skipped, unless the conversion specification includes a[, c, C or n conversion character.<p>An item is read from the input, unless the conversion specificationincludes an n conversion character.An input item is defined as the longest sequence of input bytes(up to any specified maximum field width, which may be measured incharacters or bytes dependent on the conversion character) which is aninitial subsequence of a matching sequence.The first byte, if any, after the input item remains unread.If the length of the input item is 0, the execution of theconversion specification fails;this condition is a matching failure, unless end-of-file, an encodingerror, or a read error preventedinput from the stream, in which case it is an input failure.<p>Except in the case of a % conversion character, the input item (or, in thecase of a<i>%n</i>conversion specification, the count of input bytes)is converted to a type appropriate to the conversion character.If the input item is not a matching sequence, the execution ofthe conversion specification fails; this condition is a matching failure.Unless assignment suppression was indicated by a *,the result of the conversion is placed in the object pointed toby the first argument following the<i>format</i>argument that has not already received a conversion resultif the conversion specification is introduced by %,&nbsp;or in the<i>n</i>thargument if introduced by the character sequence<i>%n$</i>.&nbsp;If this object does not have an appropriate type, or if theresult of the conversion cannot be represented in the spaceprovided, the behaviour is undefined.<p>The following conversion characters are valid:<dl compact><dt>d<dd>Matches an optionally signed decimal integer, whose format is thesame as expected for the subject sequence of<i><a href="strtol.html">strtol()</a></i>with the value 10 for the<i>base</i>argument.In the absence of a size modifier, the corresponding argumentmust be a pointer to<b>int</b>.<dt>i<dd>Matches an optionally signed integer, whose format is the same asexpected for the subject sequence of<i><a href="strtol.html">strtol()</a></i>with 0 for the<i>base</i>argument.In the absence of a size modifier, the corresponding argumentmust be a pointer to<b>int</b>.<dt>o<dd>Matches an optionally signed octal integer, whose format is the same asexpected for the subject sequence of<i><a href="strtoul.html">strtoul()</a></i>with the value 8 for the<i>base</i>argument.In the absence of a size modifier, the corresponding argumentmust be a pointer to<b>unsigned int</b>.<dt>u<dd>Matches an optionally signed decimal integer, whose format is thesame as expected for the subject sequence of<i><a href="strtoul.html">strtoul()</a></i>with the value 10 for the<i>base</i>argument.In the absence of a size modifier, the corresponding argumentmust be a pointer to<b>unsigned int</b>.<dt>x<dd>Matches an optionally signed hexadecimal integer, whose format isthe same as expected for the subject sequence of<i><a href="strtoul.html">strtoul()</a></i>with the value 16 for the<i>base</i>argument.In the absence of a size modifier, the corresponding argumentmust be a pointer to<b>unsigned int</b>.<dt>e,&nbsp;f,&nbsp;g<dd>Matches an optionally signed floating-point number, whose format isthe same as expected for the subject sequence of<i><a href="strtod.html">strtod()</a></i>.In the absence of a size modifier, the corresponding argumentmust be a pointer to<b>float</b>.If the <i><a href="fprintf.html">fprintf()</a></i>family of functions generates character stringrepresentations for infinity and NaN (a 7858 symbolic entity encodedin floating-point format) to support the ANSI/IEEE&nbsp;Std&nbsp;754:1985 standard, the <i>fscanf()</i>family of functions will recognise them as input.<dt>s<dd>Matches a sequence of bytes that are not white-space characters.The corresponding argument must be a pointer to the initialbyte of an array of<b>char</b>,<b>signed char</b>or<b>unsigned char</b>large enough to accept the sequence and aterminating null character code, which will be added automatically.

⌨️ 快捷键说明

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