HAR1F

Untitled

May 24th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int main()
  7. {
  8.    int     fd[2];
  9.    ssize_t size;
  10.    char     string[] = "Hello, world!";
  11.    char  resstring[14];
  12.  
  13.    if(pipe(fd) < 0){
  14.      printf("Can\'t open pipe\n");
  15.      exit(-1);
  16.    }
  17.  
  18.    size = write(fd[1], string, 14);
  19.  
  20.    if(size != 14){
  21.      printf("Can\'t write all string to pipe\n");
  22.      exit(-1);
  23.    }
  24.  
  25.    size = read(fd[0], resstring, 14);
  26.  
  27.    if(size < 0){
  28.       printf("Can\'t read string from pipe\n");
  29.       exit(-1);
  30.    }
  31.  
  32.    printf("%s\n", resstring);
  33.  
  34.    close(fd[0]);
  35.    close(fd[1]);
  36.  
  37.    return 0;
  38. }
Add Comment
Please, Sign In to add comment