#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#define BUFFER_SIZE 100
int main() {
int pipefd[2];
pid_t pid;
if (pipe(pipefd) == -1) {
perror("pipe");
exit(EXIT_FAILURE);
}
pid = fork();
if (pid < 0) {
perror("fork");
exit(EXIT_FAILURE);
}
if (pid > 0) { // parent process
close(pipefd[0]); // close the read end of the pipe
char message[] = "Hello, this is a message from the parent process.";
printf("Parent process sending message: %s\n", message);
write(pipefd[1], message, strlen(message) + 1);
close(pipefd[1]); // close the write end of the pipe
} else { // child process
close(pipefd[1]); // close the write end of the pipe
char received_message[BUFFER_SIZE];
read(pipefd[0], received_message, BUFFER_SIZE);
printf("Child process received message: %s\n", received_message);
for (int i = 0; received_message[i]; i++) {
if (islower(received_message[i])) {
received_message[i] = toupper(received_message[i]);
} else if (isupper(received_message[i])) {
received_message[i] = tolower(received_message[i]);
}
}
printf("Child process changing case: %s\n", received_message);
close(pipefd[0]); // close the read end of the pipe
write(pipefd[1], received_message, strlen(received_message) + 1);
}
return 0;
}