3 /* vsscanf( const char *, const char *, va_list arg )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
14 int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, va_list arg )
16 struct _PDCLIB_status_t status;
19 /* In _PDCLIB_print, status.n holds the maximum number of characters to be
20 written. As we don't need that for the scanf() functions, we (ab)use
21 this field to hold the number of matching conversion specifiers.
26 /* In _PDCLIB_print, status.s is the string *printed to*. In the scanf()
27 functions, we (ab)use this field to hold the string *scanned from*.
33 va_copy( status.arg, arg );
34 while ( *format != '\0' )
37 if ( ( *format != '%' ) || ( ( rc = _PDCLIB_scan( format, &status ) ) == format ) )
39 /* No conversion specifier, match verbatim */
40 if ( isspace( *format ) )
42 /* Whitespace char in format string: Skip all whitespaces */
43 /* No whitespaces in input do not result in matching error */
44 while ( isspace( *status.s ) )
52 /* Non-whitespace char in format string: Match verbatim */
53 if ( *status.s != *format )
68 /* Continue parsing after conversion specifier */
79 #include <_PDCLIB_test.h>
83 char const * teststring1 = "abc def";
84 char const * teststring2 = "abcdef";
85 char const * teststring3 = "abc%def";
87 TESTCASE( sscanf( teststring2, "abcdef%n", &x ) == 0 );
89 TESTCASE( sscanf( teststring1, "abc def%n", &x ) == 0 );
91 TESTCASE( sscanf( teststring2, "abc def%n", &x ) == 0 );
93 TESTCASE( sscanf( teststring3, "abc%%def%n", &x ) == 0 );