home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sams Teach Yourself C in 21 Days (6th Edition)
/
STYC216E.ISO
/
mac
/
Examples
/
Day02
/
list_it.c
< prev
next >
Wrap
C/C++ Source or Header
|
2002-04-07
|
860b
|
47 lines
/* list_it.c__This program displays a listing with line numbers! */
#include <stdio.h>
#include <stdlib.h>
void display_usage(void);
int line;
int main( int argc, char *argv[] )
{
char buffer[256];
FILE *fp;
if( argc < 2 )
{
display_usage();
return 1;
}
if (( fp = fopen( argv[1], "r" )) == NULL )
{
fprintf( stderr, "Error opening file, %s!", argv[1] );
return(1);
}
line = 1;
while( fgets( buffer, 256, fp ) != NULL )
fprintf( stdout, "%4d:\t%s", line++, buffer );
fclose(fp);
return 0;
}
void display_usage(void)
{
fprintf(stderr, "\nProper Usage is: " );
fprintf(stderr, "\n\nlist_it filename.ext\n" );
}
/* Function returns the product of the two values provided */
int product(int x, int y)
{
return (x * y);
}