FAT | RFS | XFS

putchar()

PROTOTYPE

#include <stdio.h>

int putchar(int ch);

DESCRIPTION

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

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

If successful, putchar() updates stdout’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 stdout is not the handle of a file open in write or append mode.
ENOSPC The volume is full.

EXAMPLE

/*-------------------------------------------------------------*/
/* Echo stdin to stdout until 'q' is entered.                  */
/*-------------------------------------------------------------*/
do
{
  c = getchar();
  if (putchar(c) == EOF)
    perror("error writing to output");
} while (c != 'q');