vsscanf()

Updated: April 19, 2023

Scan input from a string (varargs)

Synopsis:

#include <stdio.h>
#include <stdarg.h>

int vsscanf( const char* in_string,
             const char* format,
             va_list arg );

Arguments:

in_string
The string that you want to read from.
format
A string that specifies the format of the input. For more information, see scanf(). The formatting string determines what additional arguments you need to provide.
arg
A variable-argument list of the additional arguments, which you must have initialized with the va_start() macro.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The vsscanf() function scans input from the string designated by in_string, under control of the argument format.

The vsscanf() function is a “varargs” version of sscanf().

Returns:

The number of input arguments for which values were successfully scanned and stored is returned, or EOF when the scanning is terminated by reaching the end of the input string.

Examples:

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

void sfind( char* string, char* format, ... )
  {
    va_list arglist;

    va_start( arglist, format );
    vsscanf( string, format, arglist );
    va_end( arglist );
  }

int main( void )
  {
    int day, year;
    char weekday[10], month[12];

    sfind( "Monday June 28 1999",
        "%s %s %d %d",
        weekday, month, &day, &year );
    printf( "\n%s, %s %d, %d\n",
        weekday, month, day, year );
    return EXIT_SUCCESS;
  }

Classification:

ANSI, POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes