📄 fiolib.html
字号:
<p></blockquote><h4>RETURNS</h4><blockquote><p><p>The number of bytes read, or ERROR if there is an error during the readoperation.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./fioLib.html#top">fioLib</a></b>, <b><a href="./ioLib.html#read">read</a>( )</b><hr><a name="fioRdString"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>fioRdString( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>fioRdString( )</strong> - read a string from a file</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int fioRdString ( int fd, /* fd of device to read */ char string[], /* buffer to receive input */ int maxbytes /* max no. of chars to read */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine puts a line of input into <i>string</i>. The specified inputfile descriptor is read until <i>maxbytes</i>, an EOF, an EOS, or a newlinecharacter is reached. A newline character or EOF is replaced with EOS,unless <i>maxbytes</i> characters have been read.<p></blockquote><h4>RETURNS</h4><blockquote><p><p>The length of the string read, including the terminating EOS;or EOF if a read error occurred or end-of-file occurred withoutreading any other character.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./fioLib.html#top">fioLib</a></b><hr><a name="sscanf"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>sscanf( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>sscanf( )</strong> - read and convert characters from an ASCII string (ANSI)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int sscanf ( const char * str, /* string to scan */ const char * fmt, /* format string */ ... /* optional arguments to format string */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine reads characters from the string <i>str</i>, interprets themaccording to format specifications in the string <i>fmt</i>, which specifiesthe admissible input sequences and how they are to be converted forassignment, using subsequent arguments as pointers to the objects toreceive the converted input.<p>If there are insufficient arguments for the format, the behavior isundefined. If the format is exhausted while arguments remain, the excessarguments are evaluated but are otherwise ignored.<p>The format is a multibyte character sequence, beginning and ending inits initial shift state. The format is composed of zero or more directives:one or more white-space characters; an ordinary multibyte character (neither<b>%</b> nor a white-space character); or a conversion specification. Eachconversion specification is introduced by the <b>%</b> character. After the <b>%</b>,the following appear in sequence:<p><ul><li>An optional assignment-suppressing character <b>*</b>.</li><li>An optional non-zero decimal integer that specifies the maximum field </li>width.<li>An optional <b>h</b>, <b>l</b> (ell) or <b>ll</b> (ell-ell) indicating the size of the </li>receiving object. The conversion specifiers <b>d</b>, <b>i</b>, and <b>n</b> should be preceded by <b>h</b> if the corresponding argument is a pointer to <b>short int</b> rather than a pointer to <b>int</b>, or by <b>l</b> if it is a pointer to <b>long int</b>, or by <b>ll</b> if it is a pointer to <b>long long int</b>. Similarly, the conversion specifiers <b>o</b>, <b>u</b>, and <b>x</b> shall be preceded by <b>h</b> if the corresponding argument is a pointer to <b>unsigned short int</b> rather than a pointer to <b>unsigned int</b>, or by <b>l</b> if it is a pointer to <b>unsigned long int</b>, or by <b>ll</b> if it is a pointer to <b>unsigned long long int</b>. Finally, the conversion specifiers <b>e</b>, <b>f</b>, and <b>g</b> shall be preceded by <b>l</b> if the corresponding argument is a pointer to <b>double</b> rather than a pointer to <b>float</b>. If a <b>h</b>, <b>l</b> or <b>ll</b> appears with any other conversion specifier, the behavior is undefined.<li></blockquote><h4>WARNING</h4><blockquote><p>ANSI C also specifies an optional <b>L</b> in some of the same</li>contexts as <b>l</b> above, corresponding to a <b>long double *</b> argument.However, the current release of the VxWorks libraries does not support <b>long double</b> data; using the optional <b>L</b> gives unpredictable results.<li>A character that specifies the type of conversion to be applied. The</li>valid conversion specifiers are described below.</ul><p>The <b><a href="./fioLib.html#sscanf">sscanf</a>( )</b> routine executes each directive of the format in turn. If a directive fails, as detailed below, <b><a href="./fioLib.html#sscanf">sscanf</a>( )</b> returns. Failuresare described as input failures (due to the unavailability of inputcharacters), or matching failures (due to inappropriate input).<p>A directive composed of white-space character(s) is executed by readinginput up to the first non-white-space character (which remains unread),or until no more characters can be read.<p>A directive that is an ordinary multibyte character is executed by readingthe next characters of the stream. If one of the characters differs fromone comprising the directive, the directive fails, and the differing andsubsequent characters remain unread.<p>A directive that is a conversion specification defines a set of matchinginput sequences, as described below for each specifier. A conversionspecification is executed in the following steps:<p>Input white-space characters (as specified by the <b><a href="./ansiCtype.html#isspace">isspace</a>( )</b> function) are skipped, unless the specification includes a <b>[</b>, <b>c</b>, or <b>n</b> specifier.<p>An input item is read from the stream, unless the specification includesan <b>n</b> specifier. An input item is defined as the longest matchingsequence of input characters, unless that exceeds a specified field width,in which case it is the initial subsequence of that length in thesequence. The first character, if any, after the input item remainsunread. If the length of the input item is zero, the execution of thedirective fails: this condition is a matching failure, unless an errorprevented input from the stream, in which case it is an input failure.<p>Except in the case of a <b>%</b> specifier, the input item is converted to atype appropriate to the conversion specifier. If the input item is not amatching sequence, the execution of the directive fails: this conditionis a matching failure. Unless assignment suppression was indicated by a<b>*</b>, the result of the conversion is placed in the object pointed to bythe first argument following the <i>fmt</i> argument that has not alreadyreceived a conversion result. If this object does not have an appropriatetype, or if the result of the conversion cannot be represented in thespace provided, the behavior is undefined.<p>The following conversion specifiers are valid:<p><dl><dt><b>d</b><dd>Matches an optionally signed decimal integer whose format isthe same as expected for the subject sequence of the <b><a href="./ansiStdlib.html#strtol">strtol</a>( )</b>function with the value 10 for the <i>base</i> argument. The corresponding argument should be a pointer to <b>int</b>.<dt><b>i</b><dd>Matches an optionally signed integer, whose format is thesame as expected for the subject sequence of the <b><a href="./ansiStdlib.html#strtol">strtol</a>( )</b>function with the value 0 for the <i>base</i> argument. The corresponding argument should be a pointer to <b>int</b>.<dt><b>o</b><dd>Matches an optionally signed octal integer, whose format is thesame as expected for the subject sequence of the <b><a href="./ansiStdlib.html#strtoul">strtoul</a>( )</b>function with the value 8 for the <i>base</i> argument. Thecorresponding argument should be a pointer to <b>unsigned int</b>.<dt><b>u</b><dd>Matches an optionally signed decimal integer, whose format is the same as expected for the subject sequence of the <b><a href="./ansiStdlib.html#strtoul">strtoul</a>( )</b>function with the value 10 for the <i>base</i> argument. Thecorresponding argument should be a pointer to <b>unsigned int</b>.<dt><b>x</b><dd>Matches an optionally signed hexadecimal integer, whose format isthe same as expected for the subject sequence of the <b><a href="./ansiStdlib.html#strtoul">strtoul</a>( )</b>function with the value 16 for the <i>base</i> argument. Thecorresponding argument should be a pointer to <b>unsigned int</b>.<dt><b>e</b>, <b>f</b>, <b>g</b><dd>Match an optionally signed floating-point number, whose formatis the same as expected for the subject string of the <b><a href="./ansiStdlib.html#strtod">strtod</a>( )</b>function. The corresponding argument should be a pointer to <b>float</b>.<dt><b>s</b><dd>Matches a sequence of non-white-space characters. The corresponding argument should be a pointer to the initialcharacter of an array large enough to accept the sequenceand a terminating null character, which will be added automatically.<dt><b>[</b><dd>Matches a non-empty sequence of characters from a set of expected characters (the <b>scanset</b>). The corresponding argumentshould be a pointer to the initial character of an array largeenough to accept the sequence and a terminating null character,which is added automatically. The conversion specifierincludes all subsequent character in the format string, up toand including the matching right bracket (<b>]</b>). The charactersbetween the brackets (the <b>scanlist</b>) comprise the scanset,unless the character after the left bracket is a circumflex (<b>^</b>)in which case the scanset contains all characters that do notappear in the scanlist between the circumflex and the rightbracket. If the conversion specifier begins with "[]" or "[^]", theright bracket character is in the scanlist and the next right bracket character is the matching right bracket that endsthe specification; otherwise the first right bracket characteris the one that ends the specification.<dt><b>c</b><dd>Matches a sequence of characters of the number specified by thefield width (1 if no field width is present in the directive).The corresponding argument should be a pointer to the initial character of an array large enough to accept the sequence.No null character is added.<dt><b>p</b><dd>Matches an implementation-defined set of sequences, which should bethe same as the set of sequences that may be produced by the %pconversion of the <b><a href="./ansiStdio.html#fprintf">fprintf</a>( )</b> function. The corresponding argumentshould be a pointer to a pointer to <b>void</b>. VxWorks defines itspointer input field to be consistent with pointers written by the<b><a href="./ansiStdio.html#fprintf">fprintf</a>( )</b> function ("0x" hexadecimal notation). If the input item isa value converted earlier during the same program execution, thepointer that results should compare equal to that value; otherwisethe behavior of the %p conversion is undefined.<dt><b>n</b><dd>No input is consumed. The corresponding argument should be a pointer to<b>int</b> into which the number of characters read from the input stream sofar by this call to <b><a href="./fioLib.html#sscanf">sscanf</a>( )</b> is written. Execution of a %n directive doesnot increment the assignment count returned when <b><a href="./fioLib.html#sscanf">sscanf</a>( )</b> completesexecution.<dt><b>%</b><dd>Matches a single <b>%</b>; no conversion or assignment occurs. Thecomplete conversion specification is %%.</dl><p>If a conversion specification is invalid, the behavior is undefined.<p>The conversion specifiers <b>E</b>, <b>G</b>, and <b>X</b> are also valid and behave thesame as <b>e</b>, <b>g</b>, and <b>x</b>, respectively.<p>If end-of-file is encountered during input, conversion is terminated. If end-of-file occurs before any characters matching the current directivehave been read (other than leading white space, where permitted), executionof the current directive terminates with an input failure; otherwise, unlessexecution of the current directive is terminated with a matching failure,execution of the following directive (if any) is terminated with an inputfailure.<p>If conversion terminates on a conflicting input character, the offendinginput character is left unread in the input stream. Trailing white space(including new-line characters) is left unread unless matched by adirective. The success of literal matches and suppressed assignments isnot directly determinable other than via the %n directive.<p></blockquote><h4>INCLUDE FILES</h4><blockquote><p><b>fioLib.h</b> <p></blockquote><h4>RETURNS</h4><blockquote><p><p>The number of input items assigned, which can be fewer than provided for,or even zero, in the event of an early matching failure; or EOF if aninput failure occurs before any conversion.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./fioLib.html#top">fioLib</a></b>, <b><a href="./ansiStdio.html#fscanf">fscanf</a>( )</b>, <b><a href="./ansiStdio.html#scanf">scanf</a>( )</b>, <i>American National Standard for Information Systems -</i><i>Programming Language - C, ANSI X3.159-1989: Input/Output (<b>stdio.h</b>)</i><p>VARARGS2</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -