FAT | RFS | XFS

putc()

PROTOTYPE

#include <stdio.h>

int putc(int ch, FILE *file);

DESCRIPTION

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

putc(ch, file) is equivalent to fputc(ch, file) except putc() is implemented as both a function and a macro, so its arguments should not have side effects.

If successful, putc() updates 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 = fopen("/flash/data.txt", "r");

/*-------------------------------------------------------------*/
/* Output 'H' to stream.                                       */
/*-------------------------------------------------------------*/
if (putc('H', file) == EOF)
{
  perror("error writing to file");
  return -1;
}