每个未声明的标识符只报告一次?

时间:2013-09-21 18:41:56

标签: c process pipe

我正在编写一个程序,涉及通过定向管道进行孩子和父母之间的沟通

以下是我的代码的一部分:

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

有人可以告诉我原因吗?谢谢!

1 个答案:

答案 0 :(得分:2)

只需将WRTIE_END重命名为WRITE_END

更仔细地阅读错误消息并尝试理解它们。