I am new to c-programming, and am working with socket programming. I and want to store values from a char* buffer to different variables, but I'm having troubles storing int-values.
The data I have received from the socket is in binary and is saved in a char* buffer
, using recv()
.
The first 3 bytes of the buffer will be saved in three different unsigned char
variables, this works fine by doing:
unsigned char first = buffer[0];
unsigned char second= buffer[1];
unsigned char third = buffer[2];
Now my problem rises. I want to save the next bytes in two int variables (4 bytes each). Now I have tried:
unsigned int fourth= buffer[3];
unsigned int fifth= buffer[7];
The fourth variable holds the number 83, which is expected. However, the fifth variable is expected to be the number 1000, but what I get is 232. What am I missing here?