fork download
  1. #include<stdio.h>
  2. #include<unistd.h>
  3. #include<string.h>
  4. #include<fcntl.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("\n enter the text now...");
  14. gets(buf1);
  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,sizeof(buf2));
  19. close(fd[0]);
  20. close(fd[1]);
  21. printf("\n");
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5284KB
stdin
helloe
stdout
 enter the text now...