Anything created without the new (or malloc) keyword is created on the memory known as the stack. This includes the array created here:
When a function is called, a region of the stack is set aside for it to use. Anything created inside that function (without using new) is created in that part of the stack. When the function ends, that part of the stack becomes available for use by something else.
So, the memory that is your array: int octet;
becomes available for use when the function finishes. Clearly, something is using that memory and writing over your array. You still have a pointer to the right bit of memory - it's just being used by something else.
To get round this, either create the array outside the function and pass in a pointer to it, or create it using new (don't forget to delete when you're done with it).