如何操作字符啊?
定义了字符数组:
const uint8_t IconCmd[]
=
{0xAA,0x99,'\0'};
const uint8_t
LevelThousandCmd[]
=
{0x01,0x4F,0x00,0x8D,0x00,'\0'};
const uint8_t
LevelHundredCmd[]
=
{0x01,0x82,0x00,0x8D,0x00,'\0'};
const uint8_t
LevelTenCmd[]
=
{0x01,0xAF,0x00,0x8D,0x00,'\0'};
const uint8_t
LevelSingleCmd[]
=
{0x01,0xDC,0x00,0x8D,0x00,'\0'};
const uint8_t
LevelFractionalCmd[]
=
{0x02,0x1F,0x00,0x8D,0x00,'\0'};
想把这些字符连接起来,用sprintf函数:
CmdSize =
sprintf((char *)tmpCmd,"%s%s%c",IconCmd,LevelThousandCmd,ThousandBit);
发现这样一个故障,在连接时,Icon[2]=0x00,这个数丢失,函数认为0x0为结束符,其实
IconCmd[0] = 0xAA,IconCmd[1] = 0x99,IconCmd[2] = 0x00,IconCmd[3] = 0x00,
当函数操作到第三个数据是就认为此字符结束了;同样,LevelThousandCmd也是一样,操作到第三个数据0x00时,函数认为此字符结束了,这样就丢失了0x00,0x8D,0x00。请问该怎么处理,才能让sprintf函数实现我想要的结果?
|