mycat.c
Download mycat.c
1: /* mycat.c - a simple C program that works like "cat",
2: * only without the fancy options.
3: * It is used mainly to test the "text2html" perl script.
4: *
5: * Written 3/2007 by Wayne Pollock, Tampa Florida USA
6: */
7:
8: #include <stdio.h>
9: #include <string.h>
10:
11: void cat ( char filename[] );
12:
13: static int err_cnt = 0;
14:
15: int main ( int argc, char* argv[] )
16: {
17: while ( --argc > 0 )
18: cat( *++argv );
19: return err_cnt;
20: }
21:
22: void cat ( char filename[] )
23: {
24: int ch;
25: FILE* file;
26:
27: file = fopen( filename, "r" );
28: if ( file == NULL )
29: {
30: char err_msg[BUFSIZ] = "open failed: ";
31: perror( strcat( err_msg, filename) );
32: ++err_cnt;
33: return;
34: }
35:
36: while ( (ch = fgetc(file) ) > 0 && isascii(ch) )
37: putchar( ch );
38: fclose( file );
39:
40: return;
41: }