Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7.  
  8. int main(int argc, char **argv)
  9. {
  10. int fd = open(argv[1], O_RDWR);
  11. int counter, est = 0, tmp;
  12. long long length = 0;
  13. while(read(fd, &counter, sizeof(int))){
  14. length++;
  15. }
  16. int i;
  17. for (i = 0; i < length; i++){
  18. read(fd, &counter, sizeof(int))
  19. if(counter < 0) {
  20. est++;
  21. lseek(fd, 0, SEEK_END);
  22. write(fd, &counter, sizeof(int));
  23. lseek(fd, i + 1, SEEK_SET);
  24. }
  25. }
  26. lseek(fd, 0, SEEK_SET);
  27. for (i = 0; i < length; i++){
  28. read(fd, &counter, sizeof(int))
  29. if(counter >= 0) {
  30. lseek(fd, 0, SEEK_END);
  31. write(fd, &counter, sizeof(int));
  32. lseek(fd, i + 1, SEEK_SET);
  33. }
  34. }
  35.  
  36. for (i = 0; i < length; i++){
  37. lseek(fd, length + est - i - 1, SEEK_SET);
  38. read(fd, &counter, sizeof(int))
  39. lseek(fd, i, SEEK_SET);
  40. write(fd, &counter, sizeof(int));
  41. }
  42. close(fd);
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement