/* gtln.c
*
* Puts to stdout the nth line of the file argument.
* Useful from within shell scripts for reading files and
* assigning its lines to internal string variables.
*
* Usage: gtln n filename
*/
#include <stdio.h>
#include A HREF="stdfun.h.html"> <stdfun.h>
#define MAXLINE 514
static char _sccsid[] = { " %M% %I% %H% " };
main( argc, argv )
int argc;
char *argv[];
{
FILE *fptr, *fopen();
long linenum;
long n;
char line[MAXLINE];
int i;
if( ( fptr = fopen( argv[2], "r" ) ) == NULL ) {
fprintf( stderr, "gtln3: can't read %s\n", argv[2] );
exit( 1 );
}
sscanf( argv[1], "%ld", &n );
linenum = 0L;
while( fgets( line, MAXLINE, fptr ) != NULL ) {
if( ++linenum == n ) {
printf( "%s", line );
exit( 0 );
}
for( i = 0; i < MAXLINE; i++ )
line[i] = '\0';
}
return( 0 );
exit( 0 );
} /* end gtln.c */
Return to Home Page
Return to Metayoga Page
Return to C Language Page
The URL for this document is:
http://graham.main.nc.us/~bhammel/graham/CPROGS/gtln.html
Created: 1997
Last Updated: May 28, 2000
Email me, Bill Hammel at
bhammel@graham.main.nc.us
READ WARNING BEFORE SENDING E-MAIL