13.9. putc(), fputc(), putchar()

Write a single character to the console or to a file.


#include <stdio.h>

int putc(int c, FILE *stream);
int fputc(int c, FILE *stream);
int putchar(int c);


All three functions output a single character, either to the console or to a FILE.

putc() takes a character argument, and outputs it to the specified FILE. fputc() does exactly the same thing, and differs from putc() in implementation only. Most people use fputc().

putchar() writes the character to the console, and is the same as calling putc(c, stdout).

Return Value

All three functions return the character written on success, or EOF on error.


// print the alphabet

#include <stdio.h>

int main(void)
    char i;

    for(i = 'A'; i <= 'Z'; i++)

    putchar('\n'); // put a newline at the end to make it pretty

    return 0;

See Also