Program 12
Program 12
Write a C program to copy a text file to another, read both input file name and target
file name.
AIM:
To write a C program to copy a text file to another, read both input file name and
target file name.
ALGORITHM:
START
fptr1=fopen(filename,”r”);
STEP 3: [Open file in write mode.]
fptr2=fopen(filename,”w”);
STEP 4: [Read character from source file and write to target file]
c = fgetc(fptr1);
fputc(c, fptr2);
STEP 5: Repeat STEP 4 until EOF.
STOP
FLOWCHART:
START
fptr1=fopen(filename,”r”)
True
fptr1=NULL? A
False
fptr2=fopen(filename,”w”)
True
fptr2=NULL? A
False
C=fgetc(fptr1;)
True
Is c=EOF? Close both files.
False A
#include <stdio.h>
#include <stdlib.h> // For exit()
int main()
{
FILE *fptr1, *fptr2;
char filename[100], c;
fclose(fptr1);
fclose(fptr2);
return 0;
}
RESULT:
Thus the C program to copy a text file to another is executed successfully and output is
verified.