ccplusplus.com
Learn C, C++ Concepts
Saturday, January 7, 2012
c code to display portion of file
/******************************************************************* * File : display-portion-of-file.c * Author : Saurabh Gupta * Description : c code to display portion of file * Date : PM 10:36 07 January 2012 * Source : http://www.ccplusplus.com/p/c.html *******************************************************************/ #include
void main() { FILE *fopen(), *fp; int c , linecount; char filename[40], reply[40]; printf("Enter file name: "); gets( filename ); fp = fopen( filename, "r" ); // open for reading if ( fp == NULL ) // check does file exist etc { printf("Cannot open %s for reading \n", filename ); exit(1); /* terminate program */ } linecount = 1 ; reply[0] = '\0' ; c = getc( fp ) ; /* Read 1st character if any */ while ( c != EOF && reply[0] != 'Q' && reply[0] != 'q') { putchar( c ) ; /* Display character */ if ( c == '\n' ) linecount = linecount+ 1 ; if ( linecount == 20 ) { linecount = 1 ; printf("[Press Return to continue, Q to quit]"); gets( reply ) ; } c = getc ( fp ); } fclose( fp ); }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment