C programming putchar stdio.h


In C programming the <stdio.h> putchar function writes the character to the console.This function is similar to ‘putc’ with the second argument as ‘stdout’.The declaration of the function is given below.

int putchar(int c);

Parameters:
c -The character to be written to console.

Return type
int -Returns the character written.If a write error occurs,the error indicator for the stream is set and putchar returns EOF.

Link :C putc stdio.h

A code example is given below.

Code example

char str[]=”New string”;

int i=0 , ret;

while( i<strlen(str) )
{
ret=putchar( str[i++] );
printf(“%c ” , ret);
}

Output,

NN ee ww ss tt rr ii nn gg

The ‘ret’ value is the character written to the console.


Related links

->C fputc stdio.h