Write a program to add the contents of one file at the end of another.
#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;
}
Comments
Leave a comment