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


vfscanf

Read formatted text from a stream.

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 vfscanf(FILE *stream,
   const char *format, va_list arg);
Parameters:

Parameters for this facility are:

stream  
FILE *  
A pointer to a FILE stream  
format  
const char *  
The format string  
arg  
va_list  
The variable argument list  

Remarks:

The vfscantf() function works identically to the fscanf() function. Instead of the variable list of arguments that can be passed to fscanf(), vfscanf() 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 Vfscanf() Usage:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

int fsc(FILE *, char *, ...);

int main(void)
{
	FILE *f;
	int i;
	double x;
	char c;
	int numassigned;
	// create a new file for output and input
	if (( f = fopen("foobar", "w+")) == NULL) {
	printf("Can't create new file.\n");
	exit(1);
	}
	// output formatted text to the file
	fprintf(f, "%d\n%f\n%c\n", 45, 983.3923, 'M');
	// go to the beginning of the file
	rewind(f);
	// read from the stream using fscanf()
	numassigned = fsc(f, "%d %lf %c", &i, &x, &c);
	// close the file
	fclose(f);
	printf("The number of asssignments is %d.\n", numassigned);
	printf("The integer read is %d.\n", i);
	printf("The floating point value is %f.\n", x);
	printf("The character is %c.\n", c);
	return 0;
}

// fsc() scans an input stream and inputs
// a variable number of arguments using 
// the vfscanf() function
int fsc(FILE *stream, char *format, ...)
{
	va_list args;
	int retval;

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

=Output:
The number of asssignments is 3.
The integer read is 45.
The floating point value is 983.392300.
The character is M.


[ 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