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);
stream
: Pointer to the input stream from which the input is to be readformat
: Format in which the input will be readargs
: Pointer to the list of arguments in which data will be readIf 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,
Consider the code snippet below, which demonstrates the use of vfwscanf()
:
#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;}
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