I am receiving some data from a socket.
After that, I want to print a single byte in the received char array.
Below is the code that I used:
char buf[100];
int i = 0;
while (1)
{
rc = recv(socket_fd, buf, sizeof(buf), 0);
if (rc > 0)
{
printf("Pos1 = %x.\n", (char)buf[17]);
printf("Pos2 = %x.\n", (char)buf[22]);
}
}
But this prints out 4 bytes. If I typecast the characters to unsigned char, then single byte is printed. So what is the difference between these two typecasts, that is resulting in different number of bytes being printed.
Output:
Pos1 = 1
Pos2 = ffffff83