C Program to Copy and Merge File
Get Certified in C Programming and Take Your Skills to the Next Level
Program 1
// Program for copy file
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp1,*fp2;
char ch;
system("cls");
fp1=fopen("d://mydata/mystring.txt","r");
fp2=fopen("d://mydata/mytemp.txt","w");
if(fp1==NULL || fp2==NULL)
printf("\n File error");
else
{
while((ch=fgetc(fp1))!=EOF)
{
fputc(ch,fp2);
}
fclose(fp1);
fclose(fp2);
printf("File copied.......");
}
return 0;
}Program 2
// Program for merge file
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp1=NULL,*fp2=NULL,*fp3=NULL;
char ch;
system("cls");
fp1=fopen("d://mydata/mystring.txt","r");
fp2=fopen("d://mydata/student.txt","r");
fp3=fopen("d://mydata/stringstudent.txt","a");
if(fp1==NULL || fp2==NULL|| fp3==NULL)
printf("File error");
else
{
while((ch=fgetc(fp1))!=EOF)
{
fputc(ch,fp3);
}
fclose(fp1);
while((ch=fgetc(fp2))!=EOF)
{
fputc(ch,fp3);
}
fclose(fp2);
fclose(fp3);
printf("Merging done");
}
}Program 3
// Program for count space ,lines , letter
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
int main()
{
int lt=0,sp=0,nl=0;
FILE *fp=NULL;
char ch;
system("cls");
fp=fopen("d://mydata/student.txt","r");
if(fp==NULL)
printf("file not found");
else
{
while((ch=fgetc(fp))!=EOF)
{
if(iswspace(ch))
sp++;
else if(isupper(ch))
nl++;
else
lt++;
}
printf("\nTotal Letters : %d",lt);
printf("\nTotal Space : %d",sp);
printf("\nTotal Lines : %d",nl);
fclose(fp);
}
return 0;
}
You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

