stdio.h
Función vfprintf ANSI C
int vfprintf(FILE *stream, const char *formato, va_list argumentos);
Esta función es equivalente a fprintf, con la lista de argumentos de variables reemplazado por argumentos, que es inicializado por la macro va_start (y posiblemente por llamadas posteriores a va_arg. La función vfprintf no invoca la macro va_end.
Valor de retorno:
La función vfprintf retorna el número de caracteres transmitidos, o un valor negativo si se produce un error de salida.
Ejemplo:
#include <stdio.h>
#include <stdarg.h>
int mi_vfprintf( FILE *stream, const char *formato, ... )
{
va_list listaPtr;
int resultado=0;
va_start( listaPtr, formato );
resultado = vfprintf( stream, formato, listaPtr );
va_end( listaPtr );
return resultado;
}
int main()
{
FILE *fichero;
char nombre[11] = "datos6.dat";
unsigned int i;
fichero = fopen( nombre, "w" );
printf( "Fichero: %s -> ", nombre );
if( fichero )
printf( "creado (ABIERTO)\n" );
else
{
printf( "Error (NO ABIERTO)\n" );
return 1;
}
mi_vfprintf( fichero, "Esto es un ejemplo de usar la funcion \'vfprintf\'\n" );
mi_vfprintf( fichero, "\t 2\t 3\t 4\n" );
mi_vfprintf( fichero, "x\tx\tx\tx\n\n" );
for( i=1; i<=10; i++ )
mi_vfprintf( fichero, "%d\t%d\t%d\t%d\n", i, i*i, i*i*i, i*i*i*i );
mi_vfprintf( stdout, "Datos guardados en el fichero: %s\n", nombre );
if( !fclose(fichero) )
printf( "Fichero cerrado\n" );
else
{
printf( "Error: fichero NO CERRADO\n" );
return 1;
}
return 0;
}