Tobiahao

S01_LAB02_02

Nov 13th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. /*
  2. Napisz program, który uruchomi polecenie „wc” i przeka ż e mu na standardowe
  3. wej ś cie dowolny ci ą g znaków.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.     if(argc != 2){
  13.         fprintf(stderr,"Podano za duzo lub za malo argumentow\nUzycie: %s [ciag znakow]\n", argv[0]);
  14.         return EXIT_FAILURE;
  15.     }
  16.  
  17.     FILE *file;
  18.     char *string = argv[1];
  19.  
  20.     if((file = popen("wc", "w")) == NULL){
  21.         perror("popen");
  22.         return EXIT_FAILURE;
  23.     }
  24.  
  25.     fwrite(string, sizeof(char), strlen(string), file);
  26.  
  27.     if(pclose(file) == -1){
  28.         perror("pclose");
  29.         return EXIT_FAILURE;
  30.     }
  31.  
  32.     return EXIT_SUCCESS;
  33. }
Add Comment
Please, Sign In to add comment