hello i am new to c and practice on file handling in c....
and program of how to merging two txt file into one txt file side by side facing issue.....
there are 3 files RFID.txt,FP.txt and USERID.txt
1)In RFID.txt
ae 34 er 45
sd gg 5t t5
dd tu 66 ui
t5 y5 t5 u8
f5 h7 hh y6
2)In FP.txt
1
2
3
4
5
3)and in merging file USERID.txt
ae 34 er 45
sd gg 5t t5
dd tu 66 ui
t5 y5 t5 u8
f5 h7 hh y6
1
2
3
4
5
above is the output of program but i want following output==>
@Thomas1965 thanks for your reply...."write the line from RFID.txt and then the line from FP.txt"....cant get it. actually i have make the code of reading line by line from these two files RFID.txt and FP.txt....
The fgets() leaves the newline at the end of the string. After reading each line from RFID.txt, use strchr() to find the position of that newline and then replace that character with a space.
while (((ch1=fgetc(fa))!=EOF) && ((ch2=fgetc(fb))!=EOF))
{
if (ch1 != EOF) //getting lines in alternately from two files
{
ungetc(ch1,fa);
fgets(str1, 255,fa);
/*
After reading each line from RFID.txt,
use strchr() to find the position of the newline
and then replace that character with a space.
*/
char * nl = strchr(str1, '\n');
if (nl)
{
*nl = ' '; // replace newline with space
}
fputs(str1,fc);
}
if (ch2 != EOF)
{
ungetc(ch2,fb);
fgets(str1, 255,fb);
fputs(str1,fc);
}
}