Answer to Question #208697 in C for Muhammad Haris

Question #208697

Write a program to add the contents of one file at the end of another.  


1
Expert's answer
2021-06-19T07:00:47-0400
#include <stdio.h>
#include <stdlib.h> 


int main()
{
	FILE *ptr1;
	FILE *ptr2;
	char fileName1[20];
	char fileName2[20];
	char character;
	printf("Enter the first file name: ");
	gets(fileName1);
	ptr1 = fopen(fileName1, "r");
	if (ptr1 == NULL)
	{
		printf("The file \"%s\" does not exist...", fileName1);
	}else{
		printf("Enter the second file name: ");
		gets(fileName2);
		ptr2 = fopen(fileName2, "a");
		character = fgetc(ptr1);
		while (character != EOF)
		{
			fputc(character,ptr2);
			character = fgetc(ptr1);
		}
		fclose(ptr2);	
		fclose(ptr1);
	}


	getchar();
	getchar();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS