#include #include #include #include #include #include #include main(int argc, char *argv[]) { int pid = 0; int fd[2], ct; char buf[200]; FILE *Parent_FP, *Child_FP, *Out_File; if (pipe(fd) < 0) { fprintf(stderr,"Pipe Failed. Bailing Out.\n"); exit(-299); } pid = fork(); switch (pid) { case -1: printf("Failed fork\n"); break; case 0: /* Child code */ fprintf(stdout," I am child. \n"); close(fd[1]); Out_File = fopen("ChildData","w"); Child_FP = fdopen(fd[0], "r"); fscanf(Child_FP, "%s", buf); // while ( (fscanf(Child_FP, "%s", buf) != EOF) ) // { fprintf(stdout,"Child sez: %s", buf); // } fprintf(stdout,"\nChild sez: I am Done. \n"); fclose(Child_FP); exit(0); default: /* Parent code */ fprintf(stdout," I am parent. \n"); close(fd[0]); Parent_FP = fdopen(fd[1], "w"); // do // { fprintf(stdout," Parent Sez - Enter a string: "); fscanf(stdin, "%s", buf); fprintf(Parent_FP,"%s", buf); // } while (strcmp(buf,"DONE") == 0); fclose(Parent_FP); waitpid(pid, NULL, 0); fprintf(stdout,"\nParent sez: Child exited - I am Done. \n"); exit(0); break; } }