该程序读取文件的内容并通过管道发送它们。我在读取子进程中的管道时遇到问题。我的输出文件中的内容是方块字符。我想我必须将c从一个地址改为一个值?从C中的管道读取字符
if (pid > 0) { /* parent */
/* close the end of the pipe we do not need */
close(pfd[0]);
/* read from the input file and write to the pipe */
while ((c = getc(from)) != EOF){
if (flipping){
c = flipChar(c);
write(pfd[1],&c, 1);
}
else
write(pfd[1],&c, 1);
}
fclose(from);
close(pfd[1]);
wait(NULL);
}
else{ /* child process */
close(pfd[1]);
while (c = read(pfd[0],&c,1))
{
/* change c from a address to value?? */
putc(c, destfile);
}
fclose(destfile);
close(pfd[0]);
}
return 0;
}
任何错误输出? “有麻烦”的性质是什么? –