/* Fileprint.c (c) Kari Laitinen http://www.naturalprogramming.com/ 2013-11-28 File created. 2013-11-28 Last modification. */ #include int main() { FILE* file_to_print ; char file_name_from_user[ 20 ] ; char text_line_from_file[ 150 ] ; printf( "\n This program prints the contents of a text" "\n file to the screen. Give file name: " ) ; gets( file_name_from_user ) ; file_to_print = fopen( file_name_from_user, "r" ) ; if ( file_to_print == 0 ) { printf( "\n Cannot open file %s\n", file_name_from_user ) ; } else { int line_counter = 0 ; while ( fgets( text_line_from_file, sizeof( text_line_from_file ), file_to_print ) != 0 ) { printf( "%s", text_line_from_file ) ; line_counter ++ ; } fclose( file_to_print ) ; printf( "\n %d lines printed.\n", line_counter ) ; } }