Write an interactive C program to append the contents of a file at the end of another file without using any built-in functions – IGNOU MCA Assignment 2017 – 18

By | November 26, 2017

MASTER OF COMPUTER APPLICATIONS
Course Code: MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/2017-18
Maximum Marks : 100

Write a program to find the largest element in an array using Recursion – IGNOU MCA Assignment 2017 – 18

Program:

#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp1,*fp2,*ftemp;
char CH;
int c;
clrscr();
fp1=fopen(“TEST1.txt”,”r”);
fp2=fopen(“TEST2.txt”,”r”);
if(fp1==NULL||fp2==NULL)
{
perror(“Error has occured”);
printf(“Press any key to Exit…”);
exit(EXIT_FAILURE);
}
ftemp=fopen(“TEST3.txt”,”w”);
if(ftemp==NULL)
{
perror(“Error has occured”);
printf(“Press any key to Exit…”);
exit(EXIT_FAILURE);
}
while(1)
{ CH=fgetc(fp1);
if(feof(fp1)) break;
fputc(CH,ftemp);
}
fputc(‘\n’,ftemp);
while(1)
{ CH=fgetc(fp2);
if(feof(fp2)) break;
fputc(CH,ftemp);
}
printf(“\nTwo files merged in another file…”);
fclose(fp1);
fclose(fp2);
fclose(ftemp);
getch();
}

Code:

#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp1,*fp2,*ftemp;
char CH;
int c;
clrscr();
fp1=fopen("TEST1.txt","r");
fp2=fopen("TEST2.txt","r");
if(fp1==NULL||fp2==NULL)
{
perror("Error has occured");
printf("Press any key to Exit...");
exit(EXIT_FAILURE);
}
ftemp=fopen("TEST3.txt","w");
if(ftemp==NULL)
{
perror("Error has occured");
printf("Press any key to Exit...");
exit(EXIT_FAILURE);
}
while(1)
{ CH=fgetc(fp1);
if(feof(fp1)) break;
fputc(CH,ftemp);
}
fputc('\n',ftemp);
while(1)
{ CH=fgetc(fp2);
if(feof(fp2)) break;
fputc(CH,ftemp);
}
printf("\nTwo files merged in another file...");
fclose(fp1);
fclose(fp2);
fclose(ftemp);
getch();
}

Screen Shots:

C_Program_File_Append

C_Program_File_Append_Output