

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The source code and explanation of a simple c program that copies a source file to a destination file. The user is prompted to enter the names of both files, and the program reads the source file character by character, writing the contents to the destination file. This is a basic i/o operation in c programming.
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!


#include<stdio.h> #include<unistd.h> #include<string.h> Int main() { FILE *in_file; FILE *out_file; char ch; char f[30]; char s[30]; printf(“This program copies the source file to the destination file\n"); printf("Enter source file’s name: \n"); scanf("%s", f); if (in_file =fopen(f,"r")) { printf("Enter destination file’s name: \n"); scanf("%s", s); out_file=fopen(s, "w"); ch=getc(in_file); while(ch!=EOF) { putc(ch,out_file); ch=getc(in_file); } fclose(in_file); fclose(out_file);
printf("\n Destination file has been copied.Here you go \n"); } }