Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   negative offset (http://www.go4expert.com/forums/negative-offset-t529/)

markyjj 9Dec2005 01:11

negative offset
 
Could someone please help me with the following code:

Inout_file.seekp(((long)-1 * sizeof(int)), ios::cur);
// offset // // mode//

This code is used to move the offset back 4 bytes from the 12th byte after replacing a value in the list. The above offset is -4 in order to move the offset back and this results in the offset now being at the 8th byte. I cant understand why the offset is -4 though. Is this to do with the ‘long’ and what is the -1 for?. Also this code is worked on the basis that integers are 4 bytes.

Hope that anyone can help…thanks

shabbir 9Dec2005 10:06

Re: negative offset
 
The seekp member function sets this pointer and thus provides random-access disk file output.

Now about the code You are passing the first parameter as
-1 * sizeof(int)
Which is
-1 * 4 [As you have told integer is 4 bytes]
And so the result becomes
-4 and so seekp moves the pointer 4 bytes in the reverse direction and so it moves from 12th to 8th byte.

Thanks
Shabbir Bhimani


All times are GMT +5.5. The time now is 16:32.