-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path157.cpp
More file actions
81 lines (68 loc) · 1.45 KB
/
157.cpp
File metadata and controls
81 lines (68 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
#include<iostream>
using namespace std;
class FileConcat
{
public:
int fd1,fd2,fd3,fd4;
FileConcat(char Fname[],char Sname[],char Tname[],char NName[])
{
fd1=open(Fname,O_RDWR);
fd2=open(Sname,O_RDWR);
fd3=open(Tname,O_RDWR);
fd4=creat(NName,0777);
fd4=open(NName,O_RDWR|O_APPEND);
if(fd1==-1 || fd2==-1 || fd3==-1 ||fd4==-1)
{
cout<<"Unable to open file"<<endl;
}
else
{
cout<<"File Opened Successfully"<<endl;
}
}
void FileX()
{
char Arr[10];
int ret=0;
while((ret=read(fd1,Arr,10))!=0)
{
write(fd4,Arr,ret);
}
while((ret=read(fd2,Arr,10))!=0)
{
write(fd4,Arr,ret);
}
while((ret=read(fd3,Arr,10))!=0)
{
write(fd4,Arr,ret);
}
}
~FileConcat()
{
close(fd1);
close(fd2);
close(fd3);
close(fd4);
}
};
int main()
{
char str1[20],str2[20],str3[30],str4[30];
char ch='\0';
int iRet=0;
cout<<"Enter First File name"<<endl;
cin>>str1;
cout<<"Enter Second File name"<<endl;
cin>>str2;
cout<<"Enter Second File name"<<endl;
cin>>str3;
cout<<"Enter File name in which you wanr to copy data"<<endl;
cin>>str4;
FileConcat obj(str1,str2,str3,str4);
obj.FileX();
return 0;
}