You are on page 1of 3

OPERATING SYSTEM LAB

Assignment No. 3

Submitted by:
Muhammad Saad Awais

Submitted to:
Sir Jawad/Sir Mudassir
Roll no.:
0227-BSCS-2015

APRIL 5, 2018
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fptr1,*fptr2; // two pointers
char in_file[100],out_file[100],ch; // buffers to handle the files

fptr1=fopen("first.txt","r");
if(fptr1==NULL) // if file fails to be created
{
printf("File not created");
exit(0);
}
printf("Enter source file:"); // The file from which data is to be copied
scanf("%s",in_file);
printf("Enter destination file:"); // the file to which data is to be copied
scanf("%s",out_file);
fptr2=fopen(out_file,"w");
if(fptr2==NULL) // if file fales to be created
{
printf("File not created");
exit(0);
}
printf("This program copies the source file into destination file");
ch=fgetc(fptr1); // Get data from file character by character
while(ch!=EOF) // Continue untill the end of file is reached
{
fputc(c,fptr2); // copied the data to second file character by charater
ch=fgetc(fptr1); // get next character
}
fclose(fptr1); // closes first file
fclose(fptr2); // closes second file
}

You might also like