Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7.  
  8. int main(int argc, char **argv) {
  9.     int file = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0600);
  10.     unsigned short val;
  11.     unsigned char buf[sizeof(val)];
  12.     while (scanf("%hu", &val) == 1) {
  13.         buf[0] = val >> CHAR_BIT;
  14.         buf[1] = val;        
  15.         write(file, buf, sizeof(buf));
  16.     }
  17.     close(file);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement