vscanf, vfscanf, vsscanf, vscanf_s, vfscanf_s, vsscanf_s
Header: <stdio.h>
Reads data from the a variety of sources, interprets it according to format and stores the results into locations defined by vlist.
# Declarations
int vscanf( const char *restrict format, va_list vlist );
(since C99)
int vfscanf( FILE *restrict stream, const char *restrict format,
va_list vlist );
(since C99)
int vsscanf( const char *restrict buffer, const char *restrict format,
va_list vlist );
(since C99)
int vscanf_s(const char *restrict format, va_list vlist);
(since C11)
int vfscanf_s( FILE *restrict stream, const char *restrict format,
va_list vlist);
(since C11)
int vsscanf_s( const char *restrict buffer, const char *restrict format,
va_list vlist);
(since C11)
# Parameters
stream: input file stream to read frombuffer: pointer to a null-terminated character string to read fromformat: pointer to a null-terminated character string specifying how to read the inputvlist: variable argument list containing the receiving arguments.
# Notes
All these functions invoke va_arg at least once, the value of arg is indeterminate after the return. These functions to not invoke va_end, and it must be done by the caller.
# Example
#include <stdio.h>
#include <stdbool.h>
#include <stdarg.h>
bool checked_sscanf(int count, const char* buf, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int rc = vsscanf(buf, fmt, ap);
va_end(ap);
return rc == count;
}
int main(void)
{
int n, m;
printf("Parsing '1 2'...");
if(checked_sscanf(2, "1 2", "%d %d", &n, &m))
puts("success");
else
puts("failure");
printf("Parsing '1 a'...");
if(checked_sscanf(2, "1 a", "%d %d", &n, &m))
puts("success");
else
puts("failure");
}