Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <stdint.h>
- #include <stdio.h>
- struct Item {
- int value;
- uint32_t next_pointer;
- };
- int main(int args, char* argv[]) {
- if (args == 1) return 0;
- int input_file = open(argv[1], O_RDONLY);
- struct Item curr_item;
- curr_item.value = -1;
- curr_item.next_pointer = -1;
- if (read(input_file, &(curr_item.value), sizeof(curr_item.value)) <= 0) {
- return 0;
- }
- read(input_file, &(curr_item.next_pointer), sizeof(curr_item.next_pointer));
- while (curr_item.next_pointer > 0) {
- printf("%d ", curr_item.value);
- lseek(input_file, curr_item.next_pointer, SEEK_SET);
- read (input_file, &(curr_item.value), sizeof(curr_item.value));
- read (input_file, &(curr_item.next_pointer), sizeof(curr_item.next_pointer));
- }
- printf("%d", curr_item.value);
- close(input_file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment