I have this simple program:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static unsigned char cmd[]={
0x01,0x80,0x00,0x00,0x00
};
void printCmd(unsigned char cmd[])
{
int i;
printf("size: %zu", sizeof(cmd));
for(i=0;i<5;i++)
{
printf("0x%x\n", cmd[i]);
}
}
int main(int argc, char *argv[])
{
int i,n;
if ( argc != 2 )
{
printf("specify n sensors\n");
return 1;
}
n = atoi(*++argv);
for(i=1; i<n+1;i++)
{
//reset cmd to default
cmd[1] = 0x80;
cmd[1]|=i;
printCmd(cmd);
sleep(3);
}
return 0;
}
It gives this output:
size: 80x1
0x81
0x0
0x0
0x0
size: 80x1
0x82
0x0
0x0
0x0
size: 80x1
0x83
0x0
0x0
0x0
All is right except the size. Why does it give 80x1 as size instead of the digit 5?