/* program that mimics the "cat" command */ #include #include #define MAX_LINE 100 int main( int argc, char *argv[] ) { FILE * fp; char line[MAX_LINE]; int i = 1; /** open file from command-line arg (no error checking) **/ if ( ( fp = fopen( argv[1], "r" ) ) == NULL ) { fprintf( stderr, "ERROR: could not open file %s\n", argv[1] ); perror( "could not open file" ); return EXIT_FAILURE; } while ( fgets( line, MAX_LINE, fp ) != NULL ) { /* printf( "%s", line ); */ printf( "%6d| %s", i, line ); i++; } fclose( fp ); return 0; }