Docsity

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

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