FAT | RFS | XFS

fputc()

PROTOTYPE

#include <stdio.h>

int fputc(int ch, FILE *file);

DESCRIPTION

fputc() converts ch to type “unsigned char” and writes it as a single byte to the open regular file specified by file at its current position, or end if open in append mode.

If successful, fputc() updates the file’s status change and data modification timestamps, marks its metadata as dirty, advances its current position, and returns the character written. Otherwise, it sets errno and the file’s error indication and returns EOF.

ERROR CODES

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

EXAMPLE

FILE *file;

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

/*-----------------------------------------------------------------*/
/* Write one letter to the end of stream.                          */
/*-----------------------------------------------------------------*/
if (fputc('H', file) != 'H')
  return -1;