Format
#include <stdarg.h> #include <wchar.h> int vswscanf(const wchar_t *buffer, const wchar_t *format, va_list arg_ptr);
Language Level: ANSI
Threadsafe: Yes.
Description
The vswscanf() function reads wide data from a buffer into locations specified by a variable number of arguments. The vswscanf() function works just like the swscanf() function, except that arg_ptr points to a list of arguments whose number can vary from call to call in the program. These arguments should be initialized by va_start for each call. In contrast, the swscanf() function can have a list of arguments, but the number of arguments in that list is fixed when you compile the program.
Each argument must be a pointer to a variable with a type that corresponds to a type specifier in format-string. The format has the same form and function as the format string for the swscanf() function.
Return Value
The vswscanf() function returns the number of fields that were successfully converted and assigned. The return value does not include fields that were read but not assigned. The return value is EOF for an attempt to read at end-of-file if no conversion was performed. A return value of 0 means that no fields were assigned.
Example that uses vswscanf()
This example uses the vswscanf() function to read various data from the string tokenstring and then displays that data.
#include <stdio.h> #include <stdarg.h> #include <wchar.h> int vread(const wchar_t *buffer, wchar_t *fmt, ...) { int rc; va_list arg_ptr; va_start(arg_ptr, fmt); rc = vswscanf(buffer, fmt, arg_ptr); va_end(arg_ptr); return(rc); } int main(void) { wchar_t *tokenstring = L"15 12 14"; char s[81]; char c; int i; float fp; /* Input various data */ vread(tokenstring, L"%s %c%d%f", s, &c, &i, &fp); /* Display the data */ printf("\nstring = %s\n",s); printf("character = %c\n",c); printf("integer = %d\n",i); printf("floating-point number = %f\n",fp); } /***************** Output should be similar to: ***************** string = 15 character = 1 integer = 2 floating-point number = 14.000000 *******************************************************************/
Related Information
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.