Hi i wrote the following program for concatenating two files.
But if the contents are as follows:
a.txt:
hi
b.txt:
all
My program concatenates like this:
hi
all
But i need it like
hi all
/*
* Filename :concatenateInFirstFile.c
* Author :Uma S G
* Description :Concatenate given two files in First File
*/
#include <stdio.h>
/* MACRO DEFINITIONS */
#define MAX_LEN 1024
#define NAME_SIZE 15
/*
* Function :main
* Description :First entry point to program
* Arguments :None
*
*/
int
main() {
/* variable declaration */
char acBuff[MAX_LEN];
char acFirstFile[NAME_SIZE], acSecondFile[NAME_SIZE];
FILE *fp1;
FILE *fp2;
/* Getting files to be conctenated */
printf("\n Enter the First File Name :\t");
gets(acFirstFile);
printf("\n Enter The second File Name :\t");
gets(acSecondFile);
/* opening file for reading */
fp2 = fopen(acSecondFile, "r");
if (fp2 == NULL) {
printf("\n Unable to open the file %s for reading!!...", acSecondFile);
return (1);
}
while (fgets(acBuff, MAX_LEN, fp2) != NULL) {
/* opening file for appending */
fp1 = fopen(acFirstFile, "a");
if (fp1 == NULL) {
printf("\n Unable to open the file %s for reading!!...", acFirstFile);
return (1);
}
fputs(acBuff, fp1);
}
/* closing files */
fclose(fp1);
fclose(fp2);
return (0);
}
Please help me with this?