Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 写入标准输出时如何在管道中转换为大写_C_Unix_Pipe_Fork - Fatal编程技术网

C 写入标准输出时如何在管道中转换为大写

C 写入标准输出时如何在管道中转换为大写,c,unix,pipe,fork,C,Unix,Pipe,Fork,我正在尝试将父级作为参数传递的字符串转换为大写管道。我是在这种情况下使用的。如何将buf转换为大写?toupper()在这种情况下不起作用 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);

我正在尝试将父级作为参数传递的字符串转换为大写管道。我是在这种情况下使用的。如何将buf转换为大写?
toupper()
在这种情况下不起作用

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);

toupper
适用于一个字符-只需添加一个循环即可

i、 e

for(int i=0;i
请解释一下,
toupper()
为什么不工作。“不工作”是什么意思?“它不工作”不是一个有用的错误描述。
for (int i = 0; i < BUF_SIZE; ++i) {
   buf[i] = toupper(buff[i]);
}