Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <fcntl.h>
  6.  
  7.  
  8. int main(int argc, char** argv)
  9. {
  10.     if(argc != 2)
  11.     {
  12.         fprintf(stderr, "Usage ./main file_path");
  13.     }
  14.    
  15.     const int to_sort = open(argv[1], O_RDONLY);
  16.     dup2(to_sort, 0);
  17.  
  18.     close(to_sort);
  19.  
  20.     FILE* out = popen("sort", "r");
  21.  
  22.     char buff[200];
  23.     int readed = 0;
  24.     while((readed = fread(buff, sizeof(char), 200, out)) > 0 )
  25.     {
  26.         write(STDOUT_FILENO, buff, readed);
  27.     }
  28.     pclose(out);
  29.  
  30.     close(to_sort);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement