C Program to Copy Files: Source Code and Explanation, Exercises of Operating Systems

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

2019/2020

Uploaded on 01/30/2020

abdul-wahab-13
abdul-wahab-13 🇵🇰

1 document

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#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);
pf3

Partial preview of the text

Download C Program to Copy Files: Source Code and Explanation and more Exercises Operating Systems in PDF only on Docsity!

#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"); } }