C applet - Copies information from one disk file to another.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *fp1, *fp2; //Define pointer variables to FILE type files
char ch, filename1[100] , filename2[100]; //Define two character arrays to store two data file names
printf("input filename filename1\n");
scanf("%s", filename1); //Enter an input file name
printf("input filename filename2\n");
scanf("%s",filename2); //input an output file name
if ((fp1 = fopen(filename1, "r")) == NULL) //open Input file
{
printf("Cannot open this file\n");
exit(0);
}
if ((fp2 = fopen(filename2, "w")) == NULL) //Open output file
{
printf("Cannot open this file\n");
exit(0);
}
while (!feof(fp1)) //If the end of the input file is not encountered
{
ch = fgetc(fp1); //Read a character from the input file and temporarily put it in the variable ch
fputc(ch, fp2); //Write ch to the output file Medium
putchar(ch); //display ch on the screen
}
putchar(10); //newline after displaying all characters
fclose(fp1); //close the input file
fclose(fp2); //close the output file
system ("pause");
return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325876413&siteId=291194637