我正在编写一个涉及通过定向管道在子进程和父进程之间进行通信的 C 程序
这是我的部分代码:
char writemsg[BUFFER_SIZE] = "Sugar Lover";
char readmsg[BUFFER_SIZE];
char parrecieve[BUFFER_SIZE];
char childrecieve[BUFFER_SIZE+1];
int fd[2];
int fd2[2];
pid_t pid;
if (pipe(fd) == -1|| pipe(fd2) == -1) {
printf("Pipe failed");
return 1;
}
pid = fork();
if (pid < 0) { /* error occurred */
printf( "Fork Failed");
return 1;
}
if (pid > 0) { /* parent process */
int i =0;
close(fd[READ_END]);/* close the unused end of the pipe */
while(writemsg[i] !='\0'){
write(fd[WRITE_END],&writemsg[i] , sizeof(char));
i++;
}
close(fd[WRITE_END]);
i = 0;
close(fd2[WRTIE_END]);
while(read(fd2[READ_END], &parrecieve[i], sizeof(char))!=0){
printf("%c", parrecieve[i]);
i++;
}
close(fd2[READ_END]);
}
它在编译时提示这一行:
close(fd2[WRTIE_END]);
谁能告诉我为什么?谢谢!
最佳答案
只需将 WRTIE_END
重命名为 WRITE_END
。
更仔细地阅读错误消息并尝试理解它们。
关于c - 每个未声明的标识符只报告一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18936227/