vfscanf - C stdio.h

C examples for stdio.h:vfscanf

Type

function

From


<cstdio>
<stdio.h>

Description

Read formatted data from stream into variable argument list

Prototype

int vfscanf ( FILE * stream, const char * format, va_list arg );

Parameters

ParameterDescription
stream FILE object.
format format string
arg a variable arguments list initialized with va_start.

Return Value

On success, the function returns the number of items filled.

Demo Code


#include <stdio.h>
#include <stdarg.h>

void ReadStuff (FILE * stream, const char * format, ...)
{
  va_list args;//  w  ww.j ava 2s . co m
  va_start (args, format);
  vfscanf (stream, format, args);
  va_end (args);
}

int main ()
{
  FILE * pFile;
  int val;
  char str[100];

  pFile = fopen ("main.cpp","r");

  if (pFile ==NULL) {
    printf("error");

    return -1;
  }
  ReadStuff ( pFile, " %s %d ", str, &val );
  printf ("I have read %s and %d", str, val);
  fclose (pFile);

  return 0;
}

Related Tutorials