Format
#include <wchar.h> int swscanf(const wchar_t *buffer, const wchar_t *format, argument-list);
Language Level: ANSI
Threadsafe: Yes.
Description
The swscanf() function is equivalent of the fwscanf() function, except that the argument buffer specifies a wide string from which the input is to be obtained, rather than from a stream. Reaching the end of the wide string is equivalent to encountering end-of-file for the fwscanf() function.
Return Value
The swscanf() 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 when the end of the string is encountered before anything is converted.
The value of errno may be set EINVAL, invalid argument.
Example that uses swscanf()
This example uses the swscanf() function to read various data from the string ltokenstring, and then displays that data.
#include <wchar.h> #include <stdio.h> wchar_t *ltokenstring = L"15 12 14"; int i; float fp; char s[10]; char c; int main(void) { /* Input various data */ swscanf(ltokenstring, L"%s %c%d%f", s, &c, &i, &fp); /* If there were no space between %s and %c, */ /* swscanf would read the first character following */ /* the string, which is a blank space. */ printf("string = %s\n",s); printf("character = %c\n",c); printf("integer = %d\n",i); printf("floating-point number = %f\n",fp); }
Related Information
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.