Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdint.h>
- #include <inttypes.h>
- enum
- {
- MIN_ARGS = 2,
- SHIFT = 256,
- SIZE = 2
- };
- int
- main(int argc, char *argv[])
- {
- int fd;
- if (argc < MIN_ARGS ||
- (fd = open(argv[1], O_RDONLY)) == -1) {
- return 1;
- }
- uint8_t tmp[SIZE];
- uint16_t min = 0, min_tmp;
- int flag = 1;
- while (read(fd, &tmp, sizeof(tmp))) {
- min_tmp = tmp[0] * SHIFT + tmp[1];
- if (min_tmp % 2 == 0 && (flag || min_tmp < min)) {
- min = min_tmp;
- flag = 0;
- }
- }
- if (!flag) {
- printf("%"PRIu16"\n", min);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement