Вы находитесь на странице: 1из 2

# include <iostream>

# include <stdlib.h>
# include <string.h>
# include <sys/wait.h>
# include <unistd.h>
# include <fstream>

using namespace std;

int main(int argc,char*argv[])


{
int p[2] , p2[2];
pipe(p);
pipe(p2);

pid_t pid = fork();


if(pid == -1)
{
cout << "Error! About Program\n";
return 1;
}
if(pid == 0)
{
ifstream fin;
fin.open("input.txt");

char array[1024];
int count = 0;
while(!fin.eof())
{
char a;
fin.get(a);
array[count++] = a;
}
if(write(p[1],array,count) < 0)
{
cout << "Error! About Program\n";
return 1;
}
return 0;
}
wait(NULL);
close(p[1]);

pid = fork();
if(pid == -1)
{
cout << "Error! About Program\n";
return 1;
}
if(pid == 0)
{
char a;
char array[1024];
int count = 0;
close(p[1]);
while(read(p[0],&a,1)>0)
{
char b = a;
if((int) a >= 65 && (int) a <= 89) // A = 65 , Z = 89
{
b = (char)((int) a + 32);
}
if((int) a >= 97 && (int) a <= 121) // a = 97 , z = 121
{
b = (char)((int) a - 32);
}
array[count++] = b;
}
if(write(p2[1],array,count)<0)
{
cout << "Error! About Program\n";
return 1;
}
return 0;
}

wait(NULL);

close(p2[1]);

pid = fork();
if(pid == -1)
{
cout << "Error! About Program\n";
return 1;
}
if(pid == 0)
{
char a;
ofstream fout;
fout.open("output.txt");
while(read(p2[0],&a,1)>0)
{
fout << a;
}
return 0;
}
wait(NULL);

return 0;
}

Вам также может понравиться