Table of Contents
Previous topic Next topic
C COMPILER LIBRARY FUNCTION REFERENCE->Detailed Descriptions->scanf()
int scanf(const char* format, ...);
|format||Format control string|
|...||Arguments to receive scanned data|
This function reads formatted data from the standard input stream stdin and assigns converted values to subsequent arguments, each of which must be a pointer. The function returns when format is exhausted.
The format control string contains the following types of objects:
A conversion specification determines the conversion of the next input field. Normally the result is placed in the variable pointed to by the next argument that has not received a conversion result but it the assignment suppression character has been used, then the input field is skipped and no
- blanks or tabs which are ignored
- ordinary characters (excluding %) which are expected to match the next on-white space characters of the input stream
- conversion specifications consisting of a %, an optional assignment suppression character *, an optional number specifying a maximum field width, an optional h, l or L indicating the size of the target, and a conversion character
assignment is made.
The integer conversion characters d, i, o, u and x may be preceded by h if the argument is a pointer to a short integer and l if the argument is a pointer to long integer.
The floating point conversion characters e, f and g may be preceded by l if the argument is a pointer to double and L if the argument is a pointer to long double.
The conversion characters allowed are:
|d||int *||Decimal integer.|
|I||int *||Integer. The integer may be octal (leading 0) or hexadecimal (leading 0x or 0X).|
|o||int *||Octal integer (with or without a leading zero).|
|x||int *||Hexadecimal integer (with or without a leading 0x or 0X).|
|u||unsigned||Unsigned decimal integer.|
|c||char *||Character. The next x input characters are placed in the argument array, where x is the value of the field width or 1 if no field width is given. The normal skip white space characters is suppressed.|
|s||char *||String. The argument points to an array of characters which should be large enough to hold the string and a terminating '\0' that will be added.|
|e,f,g||float *||Floating point value consisting of an optional sign (+ or -), a series of one or more decimal digits containing a decimal point and an optional exponent (e or E) followed by an optional signed integer value.|
The function returns the number of fields successfully converted and assigned.