#include <stdio.h>
#include <conio.h>
void main(int argc,char *argv[]){
FILE *fmrg,*fd1,*fd2;
int data1[]={1,3,9,15,18,20,30};
int data2[]={2,3,5,8,9,23,28};
int i,data,tmp1,tmp2;
clrscr();
fd1 = fopen("data1.txt","w");
for(i=0;i<7;i++)
putw(data1[i],fd1);
fclose(fd1);
fd2 = fopen("data2.txt","w");
for(i=0;i<7;i++)
putw(data2[i],fd2);
fclose(fd2);
fmrg = fopen(argv[1],"w");
fd1 = fopen("data1.txt","r");
fd2 = fopen("data2.txt","r");
//merge logicwhile(!feof(fd1)){
data = getw(fd1);
putw(data,fmrg);
}
while(!feof(fd2)){
data = getw(fd2);
putw(data,fmrg);
}
fclose(fd1);
fclose(fd2);
fclose(fmrg);
printf("\n\n***After Merging Files***\n\n");
fmrg = fopen(argv[1],"r");
while(!feof(fmrg))
{
data = getw(fmrg);
printf("%5d",data);
}
fclose(fmrg);
/* //sort logic fd1 = fopen(argv[1],"r"); fd2 = fopen(argv[1],"r"); while(!feof(fd1)){ fseek(fd1,2L,SEEK_CUR); tmp1 = getw(fd1); while(!feof(fd2)){ fseek(fd2,2L,SEEK_CUR); tmp2 = getw(fd2); if(tmp1 > tmp2) */
getch();
}