putchar Function

Put a character to stdout.

Include

<stdio.h>

Prototype

int putchar(int c);

Argument

c
character to be written

Return Value

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

Remarks

Same effect as fputc with stdout as an argument.

When building with the MPLAB XC8 compiler for PIC MCUs, the putchar() function relies on the putch() function being properly defined to direct output to the required peripheral or location. Printing will not work as expected until the putch() stub (found in the pic/sources/c99/common/putch.c of your compiler distribution) is completed. See Example code for 8-bit PIC MCUs for information on defining putch() so that printed text appears in an MPLAB X IDE simulator window.

Example

#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 = putchar(*y);
} 

Example Output

This is text