int scanf(const char* kcpFormatString, ...);
Format Specifiers:
The format specification takes the following form:
%<*><width><size><type>
The '%' begins character signals the potential input into an argument, and the remaining optional fields specify the format and type of the argument (see the tables below). The asterisk field specifies that the field will be not be assigned to the next argument, but it will be read tand the argument will be skipped.
Width | Effect |
integer | Specifies the maximum number of bytes read for the argument. Fewer bytes may be read if a whitespace character is encountered. |
Size | Effect |
h | Argument types d, i, o, x, and X are specified as short. Argument type u is specified as unsigned short. Argument types c and s are specified as single byte ASCII. |
l | Argument types d, i, o, x, and X are specified as long. Argument type u is specified as unsigned long. Argument types e, E, f, g, and G are specified as double. Argument types c and s are specified as multi-byte UNICODE. |
ll | Argument types d, i, o, x, and X are specified as long long. |
L | Argument types e, E, f, g, and G are specified as long double. |
Type | Effect |
c | Read "chars" from single-byte ASCII format. |
d | Read "ints" from signed decimal integers. |
e, E, f, g, G | Read "floats" in with optional 'e' or 'E' and number for the exponent. |
i | Read "ints" from signed decimal integers, hexadecimal with '0x' or '0X' prefix or octal with a '0' prefix. |
n | Read the number of characters read in so far into an int pointer. |
o | Read "ints" from octal integers. |
s | Read a null-terminated ASCII character string. Read up to the first whitespace character. |
u | Read "ints" from unsigned decimal integers. |
x | Read "ints" from unsigned hexadecimal integers. |
#include <cstdio>
int main()
{
int iInteger = 0;
// Read a value into the integer
int iRet = scanf("%i", &iInteger);
printf("You typed: %i\n", iInteger);
return 0;
}
© 20072024 XoaX.net LLC. All rights reserved.