08-20-2008 09:10 AM
I'm writing a simple modbus software. I need to send the following string.
char str_move1[9]={0x01, 0x10, 0x99, 0x00, 0x00, 0x09, 0x12, 0x00, 0x00};
but on debugging project i receive an overflow on the 0x99.
Also strange things:
1) strlen(str_move1) give me 3 as result (I think because of the following 0x00)
2) printing the string via this for statement:
for(i=0;i<9;i++){
DebugPrintf("%002X.",str_move1[i]);
}
give me: 01.10.FFFFFF99.00.00.09.12.00.00.
Why that overflow? How can I avoid it?
08-20-2008 09:47 AM - edited 08-20-2008 09:52 AM
Hi,
1)you're right. The strlen function count the number of characters until it reaches a NULL character (0x00 value).
2) I'm not sure of what means the "002" in the format string.
Then, as far as I understand, i thinks there's a conversion problem which maybe is due to :
- your string str_move1 : it is an array of signed characters (1byte) so, one character as to be only between -128 to 127
So there's something causing trouble
Try defining an unsigned char array instead of char.
Hope it helps.
08-20-2008 09:54 AM