Advertisement
Nasekoma

4-4

Dec 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <sys/wait.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6. #include <sys/stat.h>
  7. #include <limits.h>
  8. #include <inttypes.h>
  9.  
  10. int
  11. main(int argc, char *argv[])
  12. {
  13.     int fl = open(argv[1], O_RDWR);
  14.     long long num, min = LLONG_MAX;
  15.     int curofst = 0, minofst;
  16.     while (read(fl, &num, sizeof(num)) >= 0) {
  17.         if (num < min) {
  18.             min = num;
  19.             minofst = curofst;
  20.         }
  21.         curofst += sizeof(num);
  22.     }
  23.     if (min == LLONG_MIN) {
  24.         min = 0;
  25.     } else {
  26.         min = -min;
  27.     }
  28.     lseek(fl, SEEK_SET, minofst);
  29.     write(fl, &min, sizeof(min));
  30.     close(fl);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement