Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7.  
  8. #define BUFS 1024
  9. int i=1;
  10.  
  11. int main(int argc, char **argv)
  12. {
  13. while (--argc > 0) // dopoki sa argumenty
  14. {
  15. char *nazwa = argv[i];
  16. printf(" *nazwa: %s\n", nazwa);
  17.  
  18.  
  19. int fd, n;
  20. char buf[BUFS + 1];
  21.  
  22. // open, read, write, close - niskopoziomowe
  23. if ((fd = open(nazwa, O_RDWR | O_CREAT, 0600)) == -1)
  24. perror("Blad");
  25.  
  26. // *printf - wysokopoziomowe
  27. fprintf(stderr, "Wpisz tekst, tekst zostanie zapisany do pliku data\n");
  28.  
  29. while ((n = read(fileno(stdin), buf, BUFS)) > 0) {
  30. buf[n] = '\0';
  31. write(fd, buf, n);
  32. }
  33. close(fd);
  34. i++;
  35. }
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement