【发布时间】:2015-10-16 15:27:27
【问题描述】:
此程序读取文件的内容并通过管道发送它们。我无法从子进程中的管道读取。我的输出文件方形字符中的内容。我想我必须将 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;
}
【问题讨论】:
-
任何错误输出? “遇到麻烦”的本质是什么?