[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


vsscanf

Read formatted text from a character string.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdarg.h>
#include <stdio.h>
int vsscanf(const char * s, 
   const char * format, va_list arg);
Parameters:

Parameters for this facility are:

s  
char *  
The character string to be scanned  
format  
char *  
The format string  
arg  
va_list  
The variable argument list  

Remarks:

The vsscantf() function works identically to the sscanf() function. Instead of the variable list of arguments that can be passed to sscanf(), vsscanf() accepts its arguments in the array arg of type va_list, which must have been initialized by the va_start() macro from the stdarg.h header file. The vfscanf() does not invoke the va_end macro.

On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.

For specifications concerning the output control string and conversion specifiers please see: Hypertext\xd2 " on page .

Return:

vfscanf() returns the number of items assigned, which can be fewer than provided for in the case of an early matching failure. If an input failure occures before any conversion, vfscanf() returns EOF.

See Also:

"scanf"

"fscanf"

Example Of Vsscanf() Usage:
#include <stdio.h>
#include <stdarg.h>

int ssc(char *, char *, ...);

int main(void)
{
	static char in[] = "figs cat pear 394 road 16!";
	char s1[20], s2[20], s3[20];
	int i;

	// get the words figs, cat, road, 
	// and the integer 16
	// from in and store them in s1, s2, s3, and i,
 	// respectively
	ssc(in, "%s %s pear 394 %s %d!", s1, s2, s3, &i);
	printf("%s %s %s %d\n", s1, s2, s3, i);

	return 0;
}


// ssc() scans a character string and inputs
// a variable number of arguments using 
// the vsscanf() function
int ssc(char * s, char *format, ...)
{
	va_list args;
	int retval;

	va_start(args, format);		// prepare the arguments
	retval = vsscanf(s, format, args); 
	va_end(args);					// clean the stack
	return retval;
}

Output:
figs cat road 16


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000