The_Law

Untitled

Oct 15th, 2018
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <sys/stat.h>
  4. #include <limits.h>
  5. #include <unistd.h>
  6.  
  7. int
  8. main(int argc, char* argv[])
  9. {
  10.     char *file_name = argv[1];
  11.     int outpt_file = open(file_name, O_WRONLY | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR);
  12.     if (outpt_file) {
  13.         return 1;
  14.     }
  15.  
  16.     unsigned curr;
  17.     while (scanf("%u", &curr) == 1) {
  18.         size_t n = sizeof(curr);
  19.         unsigned char s[n];
  20.         int it = n - 1;
  21.         while (it >= 0) {
  22.             s[it--] = curr;
  23.             curr >>= CHAR_BIT;
  24.         }
  25.         if (write(outpt_file, s, n) != n) {
  26.             return 1;
  27.         }
  28.     }
  29.  
  30.     close(outpt_file);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment