Segfault while using mmap in C for reading binary files
I am trying to use mmap in C just to see how it exactly works. Currently I am try to read a binary file byte by byte using mmap. My code is like this: #include <unistd.h> #include <sys/types.h> #include <sys/mman.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> int main(int argc, char *argv[]) { int fd; char *data; for ( int i = 1; i<argc; i++) { if(strcmp(argv[i],"-i")==0) fd = open(argv[i+1],O_RDONLY); } data = mmap(NULL, 4000, PROT_READ, MAP_SHARED, fd, 8000); int i = 0; notation = data [i]; // ...... } My problem occurs when I try notation = data[0] and I get a segfault . I am