Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <limits.h>
- #include <unistd.h>
- int
- main(int argc, char* argv[])
- {
- char *file_name = argv[1];
- int outpt_file = open(file_name, O_WRONLY | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR);
- if (outpt_file) {
- return 1;
- }
- unsigned curr;
- while (scanf("%u", &curr) == 1) {
- size_t n = sizeof(curr);
- unsigned char s[n];
- int it = n - 1;
- while (it >= 0) {
- s[it--] = curr;
- curr >>= CHAR_BIT;
- }
- if (write(outpt_file, s, n) != n) {
- return 1;
- }
- }
- close(outpt_file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment