#include #include #include #include #define SZBUF 256 int main(int argc, char const *argv[]){ int fd,n,l,x; long int i, offset; if (argc<3){ fprintf(stderr,"Usage : %s \r",argv[0]); exit (1); } fd=open (argv[1], O_RDONLY); if (fd==-1){ perror("Opening destination file fails"); exit (2); } i=strtol(argv[2],NULL,0); offset=i*(sizeof(int)); l=lseek(fd,offset,SEEK_SET); if(l==1){ perror("lsink failed"); close(fd); exit (3); } n=read(fd,&x,sizeof(int)); if(n==-1){ perror("Read in file failed"); close(fd); exit (4); } if(n==0){ printf("Out of range\n"); } else{ printf("The number at offset %ld is 0x%08x --> %d \n",i,x,x); } close(fd); exit(0); }