Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. [1]
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <sys/wait.h>
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <fcntl.h>
  10.  
  11.  
  12. int main() {
  13.    int file1=open("file1",O_RDONLY);
  14.    printf("Opening for write!!!!");
  15.    int file2=open("file2",O_WRONLY);
  16.    
  17.    int i=1;
  18.    if (i>1)
  19.       if (i<=100)
  20.      i++;
  21.       write(file2,&i,sizeof(int));
  22.    read(file1,&i,sizeof(int));
  23.    printf("%d\n\t",i);
  24.    close(file1);
  25.    close(file2);
  26.    
  27.    return 0;
  28. }
  29.  
  30.  
  31. [2]
  32.  
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #include <sys/wait.h>
  36. #include <unistd.h>
  37. #include <stdio.h>
  38. #include<string.h>
  39. #include <stdlib.h>
  40. #include <fcntl.h>
  41.  
  42. int main()
  43. {
  44.    printf("Opening for read!!!");
  45.    int file1=open("file1",O_WRONLY);
  46.    int file2=open("file2",O_RDONLY);
  47.    int i;
  48.    
  49.    
  50.    read(file2,&i,sizeof(int));
  51.    if (i<=100)
  52.       i++;
  53.    write(file1,&i,sizeof(int));
  54.    printf("%d\n\t",i);
  55.    close(file1);
  56.    close(file2);
  57.    
  58.    return 0;
  59.    
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement