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.

Include

<stdio.h>

Prototype

int putc(int c, FILE * stream);

Arguments

c
character to be written
stream
pointer to FILE structure

Return Value

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

Remarks

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

Example

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|
|