#include #include #include #include int main(int argc, char *argv[]){ if (argc != 3){ fprintf(stderr, "%c ", argv[0]); exit(1); } off_t offset; ssize_t nb_read; int nb, n; int fdin; fdin = open(argv[1], O_RDONLY); if (fdin == -1){ perror("File can't be opened"); exit(2); } offset = (off_t) strtol (argv[2], NULL, 0); n = lseek(fdin, offset * sizeof(int), SEEK_SET); if (!n){ perror("Offset is out of range!"); exit(3); } nb_read=read(fdin, &nb, sizeof(int)); if (nb_read < 0){ perror("File can't be read"); exit(4); } printf("The number at offset %s is %x --> %d\n", argv[2], nb, nb); return EXIT_SUCCESS; }