-1

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);
Andrei Olar
  • 2,270
  • 1
  • 15
  • 34
  • Please explain, why is `toupper()` not working. What does “not working” mean? “It doesn't work” is not a useful error description. – fuz Jan 31 '16 at 14:20
  • 1
    [Converting string to lower case in Bash shell scripting](http://stackoverflow.com/questions/2264428/converting-string-to-lower-case-in-bash-shell-scripting) – GingerPlusPlus Jan 31 '16 at 14:23

1 Answers1

1

toupper works for one character - just add a loop

i.e.

for (int i = 0; i < BUF_SIZE; ++i) {
   buf[i] = toupper(buff[i]);
}
Ed Heal
  • 59,252
  • 17
  • 87
  • 127