Syntax
#include <stdio.h> int putc(int c, FILE *stream); int putchar(int c);Description
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.
putc and putchar return the value written. A return value of EOF indicates an error.
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> #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 < sizeof(buffer)) && ((ch = putc(buffer[i], stream)) != EOF); ++i) ; return 0; /**************************************************************************** The output should be: Hello world ****************************************************************************/ }Related Information