Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- enum
- {
- BUFF_SIZE = 4,
- CHAR_SIZE = 8
- };
- int
- main(int argc, char *argv[])
- {
- unsigned char buff[BUFF_SIZE];
- int fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0600);
- int n;
- while (scanf("%d", &n) > 0) {
- buff[sizeof(buff) - 1] = (unsigned char)(n & 0x0000ff);
- buff[sizeof(buff) - 2] = (unsigned char)((n & 0x000f00) >> 8);
- buff[sizeof(buff) - 3] = (unsigned char)((n & 0x0ff000) >> 12);
- buff[sizeof(buff) - 4] = (unsigned char)((n & 0xf00000) >> 20);
- if (write(fd, buff, sizeof(buff)) == -1) {
- return 1;
- }
- }
- close(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement