Can we use write() to modify/update intermediate records in a file

Hi,

I have a database (a simple .dat file) which has multiple records (structure datatype) in it.
I would like to know if we can use write() system call to update/modify intermediate records in this file (using C). If so, could somegive give a code snippet of the same. :slight_smile:

Thanks in advance
Regards
maverix

int fd=open(filename,O_RDWR);
lseek(fd,position,SEEK_SET);
write(fd,data,datalen);
close(fd);

Hi porter,

Thank you for your inputs.

It was a simple mistake from my side.
I had copied the functions and forgot to change the parameter in the open system call from O_RDONLY to O_RDWR.

Upon seeing your reply, I realised my mistake.

Thanks for your reply.

Regards
maverix