/* Showfile.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[ 40 ] ; char character_from_file ; int character_counter = 0 ; printf( "\n\n This program prints the contents of a text" "\n file to the screen. Please, give the name" "\n of a text file: " ) ; 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 { character_from_file = getc( file_to_print ) ; while ( character_from_file != EOF ) { printf( "%c", character_from_file ) ; character_counter ++ ; character_from_file = getc( file_to_print ) ; } fclose( file_to_print ) ; printf( "\n\n %d characters were printed to the screen.\n", character_counter ) ; } }