FAT | RFS | XFS

fprintf()

PROTOTYPE

#include <stdio.h>

int fprintf(FILE *file, const char *format, ...);

DESCRIPTION

fprintf() writes formatted text to the open regular file identified by file at its current position, or end if open in append mode. format and any following arguments are interpreted according to Standard C’s output format string conventions.

If successful, fprintf() updates the file’s status change and data modification timestamps, marks its metadata as dirty, advances its current position, and returns the number of characters written. Otherwise, it sets errno and returns a negative value.

ERROR CODES

EBADF file is not the handle of a file open in write or append mode.
EFAULT format equals NULL.
ENOSPC The volume is full.
ENXIO The volume has been removed.
EROFS The volume is read-only.

EXAMPLE

FILE *file;

/*-----------------------------------------------------------------*/
/* Open file for writing.                                          */
/*-----------------------------------------------------------------*/
if ((file = fopen("/flash/temp.txt", "w")) == NULL)
  return -1;

/*-----------------------------------------------------------------*/
/* Write simple message to stream.                                 */
/*-----------------------------------------------------------------*/
if (fprintf(file, "Hello World!\n") == EOF)
  return -1;