function
<cstdio>
vscanf
int vscanf ( const char * format, va_list arg );
Read formatted data into variable argument list
Reads data from the standard input (stdin) and stores them according to parameter format into the locations pointed by the elements in the variable argument list identified by arg.
Internally, the function retrieves arguments from the list identified by arg as if va_arg was used on it, and thus the state of arg is likely to be altered by the call.
In any case, arg should have been initialized by va_start at some point before the call, and it is expected to be released by va_end at some point after the call.
Parameters
- format
- C string that contains a format string that follows the same specifications as format in scanf (see scanf for details).
- arg
- A value identifying a variable arguments list initialized with va_start.
va_list is a special type defined in <cstdarg>.
Return Value
On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file.
If a reading error happens or the end-of-file is reached while reading, the proper indicator is set (feof or ferror). And, if either happens before any data could be successfully read, EOF is returned.
If an encoding error happens interpreting wide characters, the function sets errno to EILSEQ.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
/* vscanf example */
#include <stdio.h>
#include <stdarg.h>
void GetMatches ( const char * format, ... )
{
va_list args;
va_start (args, format);
vscanf (format, args);
va_end (args);
}
int main ()
{
int val;
char str[100];
printf ("Please enter a number and a word: ");
fflush (stdout);
GetMatches (" %d %99s ", &val, str);
printf ("Number read: %d\nWord read: %s\n", val, str);
return 0;
}
| |
Possible output:
Please enter a number and a word: 911 airport
Number read: 911
Word read: airport
|
See also
- vfscanf
- Read formatted data from stream into variable argument list (function
)
- vsscanf
- Read formatted data from string into variable argument list (function
)
- fscanf
- Read formatted data from stream (function
)
- scanf
- Read formatted data from stdin (function
)