ccplusplus.com
Learn C, C++ Concepts
Friday, January 6, 2012
display content of user entered file in c
/******************************************************************* * File : display-user-entered-file.c * Author : Saurabh Gupta * Description : Prompt user for filename and display file on screen * Date : PM 10:37 06 January 2012 * Source : http://www.ccplusplus.com/p/c.html * ToDo : try to remove gets *******************************************************************/ #include <stdio.h> void main() { FILE *fopen(), *fp; int c ; char filename[40] ; printf("Enter file to be displayed: "); gets( filename ) ; fp = fopen( filename, "r"); c = getc( fp ) ; while ( c != EOF ) { putchar(c); c = getc ( fp ); } fclose( fp ); } /* * OUTPUT * [sgupta@rhel6x64 file-handling]$ gcc display-user-entered-file.c -o display-user-entered-file [sgupta@rhel6x64 file-handling]$ ./display-user-entered-file Enter file to be displayed: ccplusplus.com XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XX www.ccplusplus.com XX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [sgupta@rhel6x64 file-handling]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment