C Programming

The following characters, after the % character, in a scanf argument, have the following effect.

Modifer Meaning
d read a decimal integer
o read an octal value
x read a hexadecimal value
h read a short integer
l read a long integer
f read a float value
e read a double value
c read a single character
s read a sequence of characters, stop reading when
an enter key or whitespace character [tab or space]
[...] Read a character string. The characters inside the
brackets indicate the allow-able characters that
are to be contained in the string. If any other
character is typed, the string is terminated. If the
first characteris a ^, the remaining characters
inside the brackets indicate that typing them
will terminate the string.
* this is used to skip input fields

Example of scanf() modifiers

	int number;
	char text1[30], text2[30];

	scanf("%s %d %*f %s", text1, &number, text2);

If the user response is,

	Hello 14 736.55 uncle sam


	 text1 = hello, number = 14, text2 = uncle

and the next call to the scanf function will continue from where the last one left off, so if

	scanf("%s ", text2);

was the next call, then

	 text2 = sam

ęCopyright B Brown. 1984-1999. All rights reserved.