-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw-18.c
51 lines (48 loc) · 1.39 KB
/
hw-18.c
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
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>
int main()
{
while (1)
{
int pipes[4];
pipe(&pipes[0]);
pipe(&pipes[2]);
int status;
char in[1024] = {0};
printf("Enter something for the child to destroy:\n");
read(STDIN_FILENO, in, sizeof(char) * 1023);
write(pipes[1], in, strlen(in) * sizeof(char));
close(pipes[1]);
int forkPid;
if ((forkPid = fork()))
{
char processedLine[1024] = {0};
wait(&status);
read(pipes[2], processedLine, sizeof(processedLine));
printf("Response: %s\n", processedLine);
close(pipes[2]);
close(pipes[3]);
}
else
{
char toEdit[1024] = {0};
read(pipes[0], toEdit, sizeof(toEdit));
close(pipes[0]);
int i;
for (i = 0; i < 1024 && toEdit[i]; i++){
toEdit[i] += 1;
if (toEdit[i] == 'a' || toEdit[i] == 'A'){
toEdit[i] = '4';
}else if (toEdit[i] == 'e' || toEdit[i] == 'E'){
toEdit[i] = '3';
}else if (toEdit[i] == 'I' || toEdit[i] == 'i'){
toEdit[i] = '1';
}
}
write(pipes[3], toEdit, sizeof(toEdit));
return 0;
}
}
}