putchar
function
The putchar
is also used to put a character
on the screen. The only difference between it and putc
is
that putchar
needs only the first argument, because the
standard output is set as the file stream for putchar
.
#include <stdio.h> int putchar(int c);
The next program puts the character 'A' on the screen through the two different functions we have seen so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <stdio.h> int main(void) { int char1 = 65; /*Typically, the numeric value of A*/ char char2 = 'A'; printf("The character whose numeric value is 65 is:\n"); putc(char1,stdout); printf("And char2 has the character:\n"); putchar(char2); return 0; } |
As occurred with getc
and
getchar
, although putc
and putchar
expect variables of int
type, we can passed them arguments of
char
type, because what is internally stored of these
variables are their numeric values.