I have the following task: Modify the program to take the text from the program as the first argument (argv[1]) is read from the command line and from the child process that from the pipe A read character string in capital letters into which pipe B is written. To convert of a character to a capital letter, the C function toupper() can be used.
argv[1] is working fine, but i failed to convert the argv Text to capital letters. I have the following code:
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, char* argv[]) {
int n, fd[2], err;
int y, fd2[2], err2;
pid_t pid;
char writemessages[1][12]={"hello world"};
char readmessage[12];
err = pipe(fd);
if (err < 0) {
perror("pipe error");
exit(1);
}
err = pipe(fd2);
if (err < 0) {
perror("pipe error");
exit(1);
}
pid = fork();
if (pid < 0) {
perror("fork error");
exit(1);
}
else if (pid > 0) { /* parent */
close(fd[0]);
close(fd2[1]);
printf("Parent Process - Writing to pipe - Message is %s\n", argv[1]);
write(fd[1], argv[1], sizeof(argv[1]));
read(fd2[0], readmessage, sizeof(readmessage));
printf("Parent - Reading from pipe B - Message is %s\n", argv[1]);
sleep(1); // ps -x
printf("Child is Terminate!\n");
wait(0);
}
else { /* child */
close(fd[1]);
close(fd2[0]);
read(fd[0], readmessage, sizeof(readmessage));
printf("Child Process - Reading from pipe - Message is %s\n", readmessage);
printf("Sleep 1 Second!\n");
sleep(1);
printf("Child Process - Writing to pipe B - Message is %s\n", readmessage);
write(fd2[1], argv[1], sizeof(argv[1]));
printf("Child is exit!\n");
exit(1);
}
wait(NULL);
return 0;
}```