ILE C/C++ Run-Time Library Functions


vfwscanf() -- Read Formatted Wide Character Data

Format

#include <stdarg.h>
#include <stdio.h>
int vfwscanf(FILE *stream, const wchar_t *format, va_list arg_ptr);

Language Level: ANSI

Threadsafe: Yes.

Description

The vfwscanf() function reads wide data from a stream into locations specified by a variable number of arguments. The vfwscanf() function works just like the fwscanf() function, except that arg_ptr points to a list of arguments whose number can vary from call to call in the program. These arguments should be initialized by va_start for each call. In contrast, the fwscanf() function can have a list of arguments, but the number of arguments in that list is fixed when you compile the program.

Each argument must be a pointer to a variable with a type that corresponds to a type specifier in format-string. The format has the same form and function as the format string for the fwscanf() function.

Note:
This function is available when SYSIFCOPT(*IFSIO) is specified on the compilation command, and LOCALETYPE(*CLD) is not specified on the compilation command.

Return Value

The vfwscanf() function returns the number of fields that were successfully converted and assigned. The return value does not include fields that were read but not assigned. The return value is EOF for an attempt to read at end-of-file if no conversion was performed. A return value of 0 means that no fields were assigned.

Example that uses vfwscanf()

This example opens the file myfile for input, and then scans this file for a string, a long integer value, and a floating point value.


#include <stdio.h>
#include <stdarg.h> 
#include <wchar.h>
 
int vread(FILE *stream, wchar_t *fmt, ...)
{
	int rc;
	va_list arg_ptr;
	va_start(arg_ptr, fmt);
	rc = vfwscanf(stream, fmt, arg_ptr);
	va_end(arg_ptr);
	return(rc);
}
 
#define MAX_LEN 80
int main(void)
{
	FILE *stream;
	long l;
	float fp;
	char s[MAX_LEN + 1];
	char c;
	stream = fopen("mylib/myfile", "r");
	/* Put in various data. */
	vread(stream, L"%s", &s [0]);
	vread(stream, L"%ld", &l);
	vread(stream, L"%c", &c);
	vread(stream, L"%f", &fp);
	printf("string = %s\n", s);
	printf("long double = %ld\n", l);
	printf("char = %c\n", c);
	printf("float = %f\n", fp);
}
/*************** If myfile contains ************************
**************** abcdefghijklmnopqrstuvwxyz 343.2 ***********
********************** expected output is: *********************
string = abcdefghijklmnopqrstuvwxyz
long double = 343
char = .
float = 2.000000
*/

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]