Name
putchar
Synopsis
Writes a character to standard output
#include <stdio.h> intputchar
( intc
);
The macro putchar()
is
similar to putc()
, but rather
than writing a character to a specified file, it writes to stdout
, and hence has no FILE
pointer argument.
Example
The following example code reads the beginning of a file
repetitively, and reports its progress on stdout
.
long count; const long CYCLES = 5000;
FILE *fp = fopen( "infile.txt", "r" );
char readback[1024];
for (count = 0; count <= CYCLES; ++count)
{
/* Start output with '\r' to re-use same screen line. */
printf( "\rPerformed %li file reads. ", count );
rewind( fp );
fgets( readback, 1024, fp );
/* Scroll a new screen line every hundred cycles. */
if (count % 100 != 0) continue;putchar
( '\n' );
}
puts( "Done." );
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.