Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <fcntl.h>
- int main(int argc, char** argv)
- {
- if(argc != 2)
- {
- fprintf(stderr, "Usage ./main file_path");
- }
- const int to_sort = open(argv[1], O_RDONLY);
- dup2(to_sort, 0);
- close(to_sort);
- FILE* out = popen("sort", "r");
- char buff[200];
- int readed = 0;
- while((readed = fread(buff, sizeof(char), 200, out)) > 0 )
- {
- write(STDOUT_FILENO, buff, readed);
- }
- pclose(out);
- close(to_sort);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement