C Program To Copy One File To Another
C Program :
/* Aim: Write a program to accept two file names as command line arguments. Copy the contents of the first file to the second file such that the case of all alphabets is reversed. */ #include<stdio.h> #include<stdlib.h> #include<ctype.h> void main() { FILE *fp1,*fp2; char ch,fname[100]; printf("\n Enter the name of first file to open:- "); scanf("%s",fname); if(fp1==NULL) { printf("\n File does not exist \n \n"); exit(0); } fp1=fopen("fname","r"); printf("\n Enter the name of second file to open:- "); scanf("%s",fname); if(fp2==NULL) { printf("\n File does not exist \n \n"); exit(0); } fp2=fopen("fname","w"); while(!feof(fp1)) { ch=fgetc(fp1); if(isalpha(ch)) { if(isupper(ch)) ch=tolower(ch); else ch=toupper(ch); } fputc(ch,fp2); } printf("\n All Content Copied. \n \n"); }
/* Output of above code:-
[root@ugilinux ~]# cc e18a1.c
[root@ugilinux ~]# ./a.out
Enter the name of first file to open:- a.txt
Enter the name of second file to open:- b.txt
All Content Copied.
*/
Comments