/* Fileput.c (c) Kari Laitinen http://www.naturalprogramming.com/ 2013-11-28 File created. 2013-11-28 Last modification. */ #include int main() { FILE* output_file ; char file_name_from_user[ 20 ] ; char character_from_keyboard ; printf( "\n This program writes text you type in to a" "\n text file. Please, give first a file name: " ) ; gets( file_name_from_user ) ; output_file = fopen( file_name_from_user, "w" ) ; if ( output_file == 0 ) { printf( "\n Cannot open file %s\n", file_name_from_user ) ; } else { printf( "\n Please, start typing in text from keyboard." "\n Type in Ctrl-Z and Enter to finish. \n\n" ) ; character_from_keyboard = getchar() ; while( character_from_keyboard != EOF ) { putc( character_from_keyboard, output_file ) ; character_from_keyboard = getchar() ; } fclose( output_file ) ; } }