#include <stdio.h>
#include <conio2.h>
/*
These define statements are used in calls to functions later.
*/
#define IN_F_NAME "Test.txt" /* Filename being copied from. */
#define OUT_F_NAME "Copy.txt" /* Filename being copied to. */
#define READ "rt" /* Sets up parameters for a read only text file. */
#define WRITE "wt" /* Sets up parameters for a write only text file. */
void scrhld(void)
{
/*
Prompt the user to press a key to continue the program.
*/
printf("\t\t\tPress Any Key to Continue...\n");
/*
Wait for a key press and discard it.
*/
getch();
}
FILE * file_open(char * name, const char * params)
{
FILE * cur;
if((cur=fopen(name,params)) == NULL)
{
puts("Error Opening File");
scrhld();
exit(1);
}
return(cur);
}
void make_copy(FILE * cur_in, FILE * cur_out)
{
char temp;
while(0 == feof(cur_in))
{
fscanf(cur_in, "%c1", &temp);
fprintf(cur_out, "%c", temp);
}
}
void close_files(FILE * cur_in, FILE * cur_out)
{
fflush(cur_in);
fflush(cur_out);
fclose(cur_in);
fclose(cur_out);
}
int main(void)
{
FILE * in, * out;
in=file_open(IN_F_NAME, READ);
out=file_open(OUT_F_NAME, WRITE);
make_copy(in, out);
close_files(in, out);
scrhld();
return 0;
}