Sams Teach Yourself C in 21 Days

(singke) #1
a,e,f,g float * A floating-point number. Numbers can be input in decimal
or scientific notation.
[...] char * A string. Only the characters listed between the brackets
are accepted. Input ends as soon as a nonmatching charac-
ter is encountered, the specified field width is reached, or
Enter is pressed. To accept the ]character, list it
first:[]...]. A \0is added at the end of the string.
[^...] char * The same as [...], except that only characters not listed
between the brackets are accepted.
% None Literal %: Reads the %character. No assignment is made.

Before seeing some examples of scanf(), you need to understand the precision modi-
fiers, which are listed in Table 14.4.

TABLE14.4 The precision modifiers
Precision
Modifier Meaning
hh Specifies that a following d,i,o,u,x,X,ornconversion specifier applies to an
argument with type pointer to signed charorunsigned char.
hh When placed before the type specifier d,i,o,u,x,X,orn, the modifier hhspeci-
fies that the argument is a pointer to a signed charorunsigned char.
h When placed before the type specifier d,i,o,u,x,X,orn, the modifier hspecifies
that the argument is a pointer to type short intorunsigned short int.
l When placed before the type specifier d,i,o,u,x,X,orn, the modifier lspecifies
that the argument is a pointer to type longorunsigned long. When placed before
the type specifier a,A,e,E,f,F,g,orG, the modifier lspecifies that the argument
is a pointer to type double.
ll When placed before type specifier d,i,o,u,x,X,orn, the modifier llspecifies
that the argument is a pointer to a long longorunsigned long long.
L When placed before the type specifier a,A,e,E,f,F,g,orG, the modifier Lspeci-
fies that the argument is a pointer to type long double.

Handling Extra Characters
Input from scanf()is buffered; no characters are actually received from stdinuntil the
user presses Enter. The entire line of characters then “arrives” from stdin, and is

352 Day 14

TABLE14.3 continued
Type Argument Meaning of Type

22 448201x-CH14 8/13/02 11:12 AM Page 352

Free download pdf