該程序讀取文件的內容並通過管道發送它們。我在讀取子進程中的管道時遇到問題。我的輸出文件中的內容是方塊字符。我想我必須將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;
}
任何錯誤輸出? 「有麻煩」的性質是什麼? –