Hi all,
I have a file "myfile", i want to write a 4 bytes word to a particular place of offset 20 from the start of the file by using mmap. Can i do like this:
But i always get segmentation fault.Code:int fd, n; unsigned char *mf; fd = open("myfile", O_WRONLY); n = lseek(fd, 20, 0); mf = mmap(0, 40, PROT_WRITE, MAP_SHARED, fd, n); strcpy(mf, "care"); msync(mf, 40, MS_SYNC);
Can anyone figure out what is wrong? And how to do it?