Copy open_close_string.c into open_close_fgetstr.c and open the following program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>// for errno
int main( void ) {
FILE* inputFile;
FILE* outputFile;
char inputFilename[80] = {0};
char outputFilename[80] = {0};
fprintf( stdout , "Enter name of input file: " );
fscanf(stdin, "%80s" , inputFilename );
inputFile = fopen( inputFilename , "r" );
if( NULL == inputFile ){
fprintf( stderr, "input file: %s: %s\n", inputFilename ,
strerror( errno ) );
exit( 1 );
}
fprintf( stdout , "Enter name of output file: " );
fscanf(stdin , "%80s" , outputFilename );
outputFile = fopen( outputFilename , "w" );
if( NULL == outputFile ){
fprintf( stderr, "input file: %s: %s\n",
outputFilename , strerror( errno ) );
exit( 1 );
}
fprintf( stdout,"\"%s\" opened for reading.\n"...