I am writing a c program involving communication between child and parent by directional pipe
Here is part of my code:
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]);
}
It's complaining about this line when compiling:
close(fd2[WRTIE_END]);
Could anybody tell me why?Thanks!