I'm trying to convert the string passed by the parent as an argument into the pipe to uppercase. I was using this in this situation. How can I convert the buf to uppercase ? The toupper()
is not working in this situation.
int fd[2];
char buf[BUF_SIZE];
ssize_t numRead;
//Child
if(close(fd[1]) == -1){
fprintf(stderr, "Error closing write end of child\n");
exit(4);
}
for(;;){
if((numRead = read(fd[0], buf, BUF_SIZE)) == -1){
fprintf(stderr, "Error reading from pipe (child)\n");
exit(5);
}
if(numRead == 0){
break;
}
if(write(STDOUT_FILENO, buf, numRead) != numRead){
fprintf(stderr, "Error writing to stdout (child)\n");
exit(6);
}
}
write(STDOUT_FILENO, "\n", 1);
if(close(fd[0]) == -1){
fprintf(stderr, "Error closing read end in child\n");
exit(7);
}
_exit(0);