Guest User

Untitled

a guest
Apr 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<sys/types.h>
  3. #include<sys/stat.h>
  4. #include<fcntl.h>
  5. #include<string.h>
  6. #include<stdlib.h>
  7. char new[20],old[20];
  8. int main()
  9. {
  10. int fd[2];
  11. pid_t cd;
  12.  
  13. char rb[50];
  14. char wb[50];
  15. int rc;
  16. printf("enter name of old file and new file");
  17. gets(old);
  18. gets(new);
  19. pipe( fd );
  20.  
  21. int fo = open( old, 0 );
  22. int tf = open( new, 0666 );
  23.  
  24. if ( fo == -1 || tf == -1 ) {
  25. printf( "Opening file failed " );
  26. exit(1);
  27. }
  28. cd = fork();
  29.  
  30. if( cd == 0 ) {
  31. // inside the child prcocess
  32. close( fd[1] );
  33.  
  34. read( fd[0], rb, sizeof( rb ) );
  35. printf( "The recived string is : %s", rb );
  36.  
  37. //Writing to the target fileOpen
  38. write( tf, rb, strlen( rb ) + 1 );
  39. } else {
  40. // inside the parent process
  41. close( fd[0] );
  42. // code to read from a text file
  43.  
  44. while( (rc = read( fo, rb, sizeof( rb ) ) > 0 ) ) {
  45. write( fd[1], rb, sizeof( rb ) );
  46. }
  47. close( fd[1] );
  48. }
  49. }
Add Comment
Please, Sign In to add comment