fork download
  1. #include<stdio.h>
  2. #include<fcntl.h>
  3. #include<string.h>
  4. #include<unistd.h>
  5. int main()
  6. {
  7. int fd[2];
  8. char buf1[25] = "Just a test\n";
  9. char buf2[50];
  10. fd[0] = open("file1",O_RDWR);
  11. fd[1] = open("file2",O_RDWR);
  12. write(fd[0],buf1,strlen(buf1));
  13. printf("\nEnter the text now....");
  14. fgets(buf1,sizeof(buf1),stdin);
  15. write(fd[0],buf1,strlen(buf1));
  16. lseek(fd[0],SEEK_SET,0);
  17. read(fd[0],buf2,sizeof(buf1));
  18. write(fd[1],buf2,strlen(buf2));
  19. close(fd[0]);
  20. close(fd[1]);
  21. printf("\n");
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Enter the text now....