gogagum

6_1

Nov 6th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <sys/stat.h>
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6.  
  7. struct Item {
  8.   int value;
  9.   uint32_t next_pointer;
  10. };
  11.  
  12. int main(int args, char* argv[]) {
  13.     if (args == 1) return 0;
  14.     int input_file = open(argv[1], O_RDONLY);
  15.     struct Item curr_item;
  16.     curr_item.value = -1;
  17.     curr_item.next_pointer = -1;
  18.     if (read(input_file, &(curr_item.value), sizeof(curr_item.value)) <= 0) {
  19.         return 0;
  20.     }
  21.     read(input_file, &(curr_item.next_pointer), sizeof(curr_item.next_pointer));
  22.     while (curr_item.next_pointer > 0) {
  23.         printf("%d ", curr_item.value);
  24.         lseek(input_file, curr_item.next_pointer, SEEK_SET);
  25.         read (input_file, &(curr_item.value),        sizeof(curr_item.value));
  26.         read (input_file, &(curr_item.next_pointer), sizeof(curr_item.next_pointer));
  27.     }
  28.     printf("%d", curr_item.value);
  29.     close(input_file);
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment