Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- void Error(char* msg){printf("%s\n",msg);exit(1);}
- int main(int argc, char* argv[]){
- int file1, file2, answer, flag1, flag2, temp;
- char buffer[1];
- if(argc < 3)
- Error("Not enough files at argv[]");
- file1 = open(argv[1], O_RDONLY, 4);
- if(file1 == -1)
- Error("Can't open the file in arg[1]");
- file2 = open(argv[2], O_RDONLY, 4);
- if(file2 == -1)
- Error("Can't open the file in arg[2]");
- answer = open(argv[3], O_RDWR | O_CREAT,0644);
- if(answer == -1)
- Error("Can't open the file in arg[3]");
- do{
- do{
- temp = read(file1,buffer,1);
- if(temp == -1)
- Error("Can't read from file in arg[1]");
- if(!temp)
- {
- flag1=1;
- break;
- }
- temp = write(answer,buffer,1);
- if(temp==-1)
- Error("Can't write to file in arg[3]");
- }while(buffer[0]!='\n');
- do{
- temp = read(file2,buffer,1);
- if(temp==-1)
- Error("Can't read from file in arg[2]");
- if(!temp)
- {
- flag2=1;
- break;
- }
- temp = write(answer,buffer,1);
- if(temp==-1)
- Error("Can't write to file in arg[3]");
- }while(buffer[0]!='\n');
- }while(flag1!=1 && flag2!=1);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment