i think you problem may come from you write in a buffer not large enough.
do this :
1. get the number of characters in the file to be exctracted.
2. allocate your buffer with that number of bytes.
3. read() the totality of the file ; it will never overflow the buffer (considering the memory is correctly allocated)
until now i used the definition 'id' which gave me the right value ( = 0x00006964 ).
because i compile under window, mac and linux and the mac gcc compiler complains about wrong 4-byte-characters i added '\0\0id' to the definition which should give in my opinion the same result. but the vc++ and intel c++ compiler generates other values.
'id' = 0x00006964
'\0\0id' = 0x64690000
' id' = 0x20206964
'\40\40id' = 0x64692020
the most interesting things are the last 2 lines. what is the difference between a space written as space or as a esc-character? ... why does the compiler generates swapped values?
that doesn't makes sense to me ... any hints would be great ...
if running this code f results in 0x64690000 ... that's exactly the same what the compiler generates with the constant '\0\0id' .. and that's swapped compared to 'id' which results in 0x00006964 ?!?!?!?!
this is one of the days where i don't understand compilers ... i want that the compiler generates the same constant when i write 'id' and '\0\0id' because this is obviously the same (for me!)
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho