ptg10805159
Section 5.11Formatted I/O 163
Conversion Description
type
d signed decimal, base 10
i signed decimal, base determined by format of input
o unsigned octal (input optionally signed)
u unsigned decimal, base 10 (input optionally signed)
x,X unsigned hexadecimal (input optionally signed)
a,A,e,E,f,F,g,G floating-point number
c character (withllength modifier,wide character)
s string (withllength modifier,wide character string)
[ matches a sequence of listed characters, ending with]
[ˆ matches all characters except the ones listed, ending with]
p pointer to avoid
n pointer to a signed integer into which is written the number of characters read so far
% a%character
C wide character(XSI option, equivalent tolc)
S wide character string(XSI option, equivalent tols)
Figure 5.10The conversion type component of a conversion specification
specifiers to force a memory buffer to be allocated to hold the converted string. In this
case, the corresponding argument should be the address of a pointer to which the
address of the allocated buffer will be copied. If the call succeeds, the caller is
responsible for freeing the buffer by calling thefreefunction when the buffer is no
longer needed.
The scanf family of functions also supports the alternative conversion
specification syntax allowing the arguments to be named explicitly: the sequence%n$
represents thenth argument. With theprintffamily of functions, the same numbered
argument can be referenced in the format string morethan once. In this case, however,
the Single UNIX Specification states that the behavior is undefined with thescanf
family of functions.
Like theprintffamily,thescanffamily supports functions that use variable
argument lists as specified by<stdarg.h>.
#include <stdarg.h>
#include <stdio.h>
int vscanf(const char *restrictformat,va_listarg);
int vfscanf(FILE *restrictfp,const char *restrictformat,
va_list arg);
int vsscanf(const char *restrictbuf,const char *restrictformat,
va_list arg);
All three return: number of input items assigned,
EOFif input error or end of file beforeany conversion
Refer to your UNIX system manual for additional details on thescanffamily of
functions.