What is vfwscanf() in C?

vfwscanf() reads a formatted list of arguments from an input stream. The declaration for vfwscanf() is shown below:

int vfwscanf( FILE *stream, const wchar_t *format, va_list args);

Parameters

  • stream: Pointer to the input stream from which the input is to be read
  • format: Format in which the input will be read
  • args: Pointer to the list of arguments in which data will be read

Return value

If the read operation from the input stream is successful, vfwscanf() returns the number of arguments that are read. If the read operation is not successful, EOFEnd-of-File is returned.

Example

Consider the code snippet below, which demonstrates the use of vfwscanf():

main.c
vfwscanfExample.txt
#include <stdio.h>
#include <wchar.h>
#include <stdarg.h>
int readformatted (FILE * stream, const wchar_t * format, ...)
{
int len=0;
va_list arg_list;
va_start (arg_list, format);
len = vfwscanf (stream, format, arg_list);
va_end (arg_list);
return len;
}
int main ()
{
FILE * fPointer = fopen ("vfwscanfExample.txt","r");
if(fPointer == NULL){
printf("%s Could not open file!!");
} else{
wchar_t buff[200];
int len = readformatted(fPointer,L" %s",buff);
printf("File Content: %s \n", buff);
printf("Number of arguments read from file: %d \n", len);
fclose (fPointer);
}
return 0;
}

Explanation

The fopen() function is used in line 17 to open the file for reading. The readformatted() function is used in line 23, which uses vfwscanf() in line 9 to read the content of the file.

Free Resources

HowDev By Educative. Copyright ©2025 Educative, Inc. All rights reserved