Prog#231: merge 2 files


#1
/*
merge 2 files
Program#231
*/
#include<stdio.h>
main(int argc,char *argv[])
{
int i,p,q,r;
char a[512];
if(argc!=4)
{
printf("error: no.of arg");
return 0;
}
p=open(argv[1], 0);
if(p==-1)
{
printf("file open error");
return 0;
}
q=open(argv[2], 0);
if(q==-1)
{
printf("file open error");
return 0;
}
r=open(argv[3], 1);
if(r==-1)
{
printf("file open error");
return 0;
}
i=read(p,a,512);
while(i>0)
{
i=write(r,a,i);
i=read(p,a,512);
}
i=read(q,a,512);
while(i>0)
{
i=write(r,a,i);
i=read(q,a,512);
}
close(p);
close(q);
close(r);
}