putc Function

Puts a character to the stream.

Attention: This function is not implemented by MPLAB XC8 for PIC MCUs. It is implemented by all other compilers, but MPLAB XC8 for AVR MCUs has limited support of data streams.




int putc(int c, FILE * stream);


character to be written
pointer to FILE structure

Return Value

Returns the character or EOF if an error occurs or end-of-file is reached.


The putc function performs the same task as the function fputc.


See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <stdio.h>

int main(void)
  char *y;
  char buf[] = "This is text\n";
  int x;

  x = 0;
  for (y = buf; (x != EOF) && (*y != '\0'); y++)
    x = putc(*y, stdout);
    putc('|', stdout);

Example Output

T|h|i|s| |i|s| |t|e|x|t|