Chapter Contents |
Previous |
Next |
vscanf |
Portability: | C99 |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
IMPLEMENTATION | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <stdarg.h> #include <lcio.h> int vscanf( const char *format, va_list arg );
DESCRIPTION |
vscanf
reads formatted
input from stdin
according to the format specified
by the string format. Following the format in the argument list is a pointer
to a list of arguments, designated by arg
,
of type va_list
as defined in the header <stdarg.h>
.
The string pointed to by format
is in
the same form as that used by fscanf
. See the fscanf
description for detailed information concerning the
formatting conventions.
RETURN VALUE |
vfscanf
returns EOF
if end of file (or an input error) occurs before any
values
are stored. If values are stored, it returns the number of items stored; that
is, the number of times a value is assigned to a member of the variable argument
list.
IMPLEMENTATION |
vscanf
is functionally
equivalent to scanf
, except that the argument
list has been replaced by a variable argument list, va_list
, as defined in the header <stdarg.h>
.
EXAMPLE |
#include <stdarg.h> #include <lcio.h> #include <stdlib.h> int DoScan(const char *fmt, ...); double point[40]; main() { int index = 0; double sum = 0.0; double avg; int nopoints; int stdn_fn = 0; /* If stdin is the terminal, fileno(stdin) is always 0. */ if (isatty(stdn_fn)) /* Tell user to enter data points; maximum = 39. */ puts("Enter data points (EOF to indicate end of list)."); for(;;) { /* Read number; check for end of file. */ if (DoScan("%le", &point[index]) == EOF) break; sum += point[index]; ++index; } nopoints = index; avg = sum / nopoints; printf("%d points read.\n", nopoints); printf("%lf = average.\n", avg); } int DoScan(const char *fmt, ...) { int n = 0; va_list args; va_start(args, fmt); n = vscanf(fmt, args); va_end(args); return n; }
RELATED FUNCTIONS |
vfprintf
, scanf
, va_arg
,
va_start
, va_end
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2004 by SAS Institute Inc., Cary, NC, USA. All rights reserved.