This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Array and Long manipulations

Hi everyone,

I have an array eg:

command[9] = {0x3C , 0x4A , 0x33 , 0x25 , 0xB1 , 0xD3 , 0x59 , 0x34 , 0x2E }

the last 4 byte is the value (in hex) that I need to manipulate, let say increment by 3.

and after manipulation I need to send back the value together with other data in one array to serial port.

What I had try is:

//init outside
unsigned char k[4];
long value;

k[0] = command [5]; k[1] = command [6]; k[2] = command [7]; k[3] = command [8];

value= strtol (k, NULL, 4);
value= value+3;
sprintf ( k, "%Ld\n"  , value);

buf[4] = k[0]; buf[5] = k[1]; buf[6] = k[2]; buf[7] = k[3];

sendcom ( buf , 15);//send to serial function


But it not working.

Can anyone give me help, and honestly I'm lack of C basics

Thanks

Juru

0