SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 266 | Next

Shon Harris, Allen Harper, Chris Eagle, and Jonathan Ness

"Gray Hat Hacking, Second Edition"


The second format allows for more flexibility through the use of a format string that can
be comprised of normal characters and special symbols that act as placeholders for the
list of variables following the comma. Commonly used format symbols are shown in
Table 6-2.
These format symbols may be combined in any order to produce the desired output.
Except for the \n symbol, the number of variables/values needs to match the number of
symbols in the format string; otherwise, problems will arise, as shown in Chapter 8.
scanf
The scanf command complements the printf command and is generally used to get
input from the user. The format is as follows:
scanf(, );
where the format string can contain format symbols such as those shown in printf. For
example, the following code will read an integer from the user and store it into the variable
called number:
scanf("%d", &number);
Actually, the & symbol meanswe are storing the value into the memory location pointed
to by number; that will make more sense when we talk about pointers later. For now,
realize that you must use the & symbol before any variable name with scanf. The command
is smart enough to change types on the fly, so if you were to enter a character in
the previous command prompt, the command would convert the character into the decimal
(ASCII) value automatically.


Pages:
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278