Problem with reading a file
Posted on 2004-08-18
Sometimes i found a very strange problem when i read from a file.
I open a file in read mode as well as binary mode. Let i have a structure which has three fileds. each field has size of 4 bytes each. so total size of structure is 12 bytes.
I'm using _read() function to read from file. _lseek() is used to seek in file. suppose i want to read from offset 0x2100 in file.
_lseek(fp,0x2100, SEEK_SET); where fp is int fp;(file descriptor)
_read(fp,buf,12); buf is object/variable of structure. size of buf is 12 bytes.
first time i read 12 bytes at offset 0x2100. then i read next 12 bytes, then next 12 .....
Most time function is successful. say after reading 12 bytes 6 times,when i read next 12 bytes sometimes function read 4 or 5 bytes and sometimes it read no byte while file has data at this particular offset. I have used #progrma pack(push,1) and #progrma pack(pop). but no success. I have tried by using fseek function in which i take FILE pointer to read from file but same problem. I don't know how to solve this problem. so please help me in this regard.