
A-42
Motorola DSP56000 Family Optimizing C Compiler User’s Manual
For More Information On This Product,
Go to: www.freescale.com
Motorola
A.4.38 fscanf—Read formatted input from a stream
#include <stdio.h>
int fscanf ( FILE *stream, const char *format, ... );
The function
fscanf
reads input from the specified stream. It uses the string
format
as a
guide for interpreting the input and storing values in memory. Subsequent arguments to
fscanf
are used as pointers to objects in memory that will receive the input values read
from the stream.
The format string is composed of directives. These are parsed from left to right from the
format string, and indicate how the input from the specified stream should be processed.
If
fscanf
fails to apply a directive, then it returns. Directives are composed of either
white-space characters or normal characters. White space character sequences indicate
that
fscanf
should read input from the specified stream up to the first non-white-space
character. Directives that consist of non-white-space characters are processed in the
following manner: input is read from the specified stream until the input character is not a
member of the set of characters comprising the directive. Finally, directives can be
conversion specifications; these directives begin with the ‘%’ character. They describe
how
fscanf
should parse input, and how
fscanf
should synthesize a value to be stored
in memory.
Conversion specifications are processed as follows. First, the stream is read until all
white-space characters have been exhausted, unless ‘[‘, ‘c’, or ‘n’ is part of the conversion
specification. Second, a value is derived from the input stream according to the conversion
specifier. A conversion specifier may be one of the following as shown in Table A-6:
Table A-6. Conversion Specifyers
Conversion
Specifyer
Description
‘d’
match a signed, decimal integer.
‘i’
match a signed integer, whose base is determined in the same manner as a C integer constant.
‘o’
match an octal integer.
‘u’
match an unsigned, decimal integer.
‘x’
match a signed, hexadecimal integer. (
‘X’
is also valid).
‘e’,’f’,’g’
match a floating-point number. (
‘E’
,
’F’
and
’G’
are also valid).
‘s’
match a sequence of non-white-space characters, essentially scan a token string.
‘[‘
match a non-empty sequence of characters from a set of expected characters, which are
bounded by a following
‘]’
.
F
Freescale Semiconductor, Inc.
n
.