December 2005
Beginner to intermediate
618 pages
20h 19m
English
putchar
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.
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." );Read now
Unlock full access