We can now create a program to open a file for reading and another file for writing. This is where our file I/O exploration will begin and will continue through the remaining chapters of this book. The following program is our starting point:
#include <stdio.h>
#include <stdlib.h> // for exit()
#include <string.h> // for strerror()
#include <sys/errno.h>// for errno
int main( void ) {
FILE* inputFile;
FILE* outputFile;
char inputFilename[] = "./input.data";
char outputFilename[] = "./output.data";
inputFile = fopen( inputFilename , "r" );
if( NULL == inputFile ){
fprintf( stderr, "input file: %s: %s\n",
inputFilename , strerror( errno ) );
exit( 1 );
}
outputFile = fopen( outputFilename , "w" );
if( NULL == outputFile ){
fprintf( stderr, "input file: %s: %s\n",
outputFilename , strerror( errno ) );
exit( 1 );
}
fprintf( stderr,"...