Read formatted text from a stream.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdarg.h>
#include <stdio.h>
int vfscanf(FILE *stream,  
const char *format, va_list arg);
Parameters for this facility are:
On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.
Return: See Also: 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