Advertisement
Tobiahao

S01_LAB02_01

Nov 13th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. /*
  2. Napisz program, który wywo ł a polecenie „sort nazwa.c”, gdzie nazwa.c jest
  3. nazwą pliku z kodem ź ród ł owym programu, a nast ę pnie odczyta 20 znaków
  4. zwróconych przez to polecenie i wy ś wietli je na ekran.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. #define BUFFER_SIZE 20
  11. #define COMMAND "sort 01.c"
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15.     char buffer[BUFFER_SIZE];
  16.     FILE *file;
  17.    
  18.     if((file = popen(COMMAND, "r")) == NULL){
  19.         perror("popen");
  20.         return EXIT_FAILURE;
  21.    
  22.     }
  23.  
  24.     fread(buffer, sizeof(char), BUFFER_SIZE, file);
  25.     buffer[BUFFER_SIZE] = '\0';
  26.     printf("%s\n", buffer);
  27.  
  28.     if(pclose(file) == -1){
  29.         perror("pclose");
  30.         return EXIT_FAILURE;
  31.     }
  32.  
  33.     return EXIT_SUCCESS;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement