putc - putchar -- Write a Character

Format

#include <stdio.h>
int putc(int c, FILE *stream);
int putchar(int c);

Language Level: ANSI, POSIX, XPG4
putc converts c to unsigned char and then writes c to the output stream at the current position. putchar is equivalent to putc(c, stdout).

putc is equivalent to fputc except that, if it is implemented as a macro, putc can evaluate stream more than once. Therefore, the stream argument to putc should not be an expression with side effects.

Return Value
putc and putchar return the character written. A return value of EOF indicates an error.

Example
This example writes the contents of a buffer to a data stream. In this example, the body of the for statement is null because the example carries out the writing operation in the test expression.

#include <stdio.h>
#include <string.h>
#define LENGTH 80
int main(void)
{
   FILE *stream = stdout;
   int i, ch;
   char buffer[LENGTH + 1] = "Hello world";
   /* This could be replaced by using the fwrite routine */
   for ( i = 0;
        (i < strlen(buffer)) && ((ch = putc(buffer[i], stream)) != EOF);
         ++i);
   return 0;
   /********************************************************************
      The output should be:
      Hello world
   ********************************************************************/
}


fputc -- Write Character
_fputchar -- Write Character
fwrite -- Write Items
getc - getchar -- Read a Character
_putch -- Write Character to Screen
puts -- Write a String
write -- Write from Buffer to File
<stdio.h>