How to rewrite a particular block of file
I want to rewrite a particular block in a file but its not working for me
For example if I want to rewrite to offset 4 of the file I used lseek(fd,4,SEEK_SET) and calle开发者_StackOverflow社区d write system call but its writing at the end of the file instead of at offset 4.
Don't use O_APPEND
. It will append everything to the end of the file, regardless of your seeking.
Use:
open("file.txt", O_RDWR);
You're assuming the file already exists, so I don't see why you would use O_CREAT
.
精彩评论