/* mycat.c - a simple C program that works like "cat", * only without the fancy options. * It is used mainly to test the "text2html" perl script. * * Written 3/2007 by Wayne Pollock, Tampa Florida USA */ #include #include void cat ( char filename[] ); static int err_cnt = 0; int main ( int argc, char* argv[] ) { while ( --argc > 0 ) cat( *++argv ); return err_cnt; } void cat ( char filename[] ) { int ch; FILE* file; file = fopen( filename, "r" ); if ( file == NULL ) { char err_msg[BUFSIZ] = "open failed: "; perror( strcat( err_msg, filename) ); ++err_cnt; return; } while ( (ch = fgetc(file) ) > 0 && isascii(ch) ) putchar( ch ); fclose( file ); return; }