I am trying to scan a short int
(16 bits/2 bytes) from a memory pointer using sscanf
as shown below. But it is showing some weird behaviour.
#include <stdio.h>
#include <errno.h>
int main()
{
unsigned char p[] = {0x00, 0x1A};
short int s = 0;
int ret = sscanf(p,"%hu",&s);
printf("Actual data %02x %02x\n",p[0],p[1]);
printf("s = %hu ret = %d errno = %d\n",s,ret,errno);
return 0;
}
Output:
Actual data 00 1a
s = 0 ret = -1 errno = 0
Please help me to understand what I am doing wrong !