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

标签 c process pipe

我正在编写一个涉及通过定向管道在子进程和父进程之间进行通信的 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/

相关文章:

c - gcc-10.0.1 特定的段错误

c - 如何在编译时打印结构成员的偏移量?

linux - 如何设置父进程的工作目录?

c - pselect 通知两个管道读端文件描述符,即使只有一个写端被写入

shell - < 生成子 shell 时的文档在哪里

rust - 有没有一种跨平台的方法来检查stdout是否通过管道传递到Rust中的另一个程序中?

C 函数头生成器

c - 为什么输出后不能跟输入,反之亦然?

Python:从 multiprocessing.Process 获取回溯

node.js - 解压streams2管道并清空它的正确方法(不仅仅是刷新)