char数组中的0x00看不到的问题

网络调试助手发来的数据:

7E 24 00 00 01 01 02 03 04 05 7E 03 7D 09 52 01 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03

QT收到的数据:

QByteArray tempArray: “~$\x00\x00\x01\x01\x02\x03\x04\x05~\x03}\tR\x01\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03
在这里插入图片描述
当我把接收到的 ~ $ \x00 三个字节的数据拷贝新建的数组frame_head中时,

char frame_head[3] = {0};
memcpy(&frame_head,tempArray.data(),sizeof(frame_head));

之后打印结果:

1
qDebug() <<"得到的结果"<<  frame_head[0] << frame_head[1] << frame_head[2];
// 结果:126 36 
无法得到frame_head[2]的数据。
2
qDebug() <<"得到的结果"<<  frame_head[0] << frame_head[1] << frame_head[2] <<"abc";
// 结果:126 36 
无法得到frame_head[2]和"abc"。这样一来abc也无法得到了。
3
qDebug() <<"得到的结果"<<  frame_head[0] << frame_head[1] << frame_head[2] <<"abc";
qDebug() << "efg"
// 结果:126 36 
		 	 "efg"
这样可以得到下面打印的数据"efg"。
4
但是,当把frame_head定义为uchar类型时,可以得到结果:126 36 0

这是为什么呢?
找了一下问题原因,但不知道是不是这个问题的解释。
里面说char数组中的0x00就是’\0’了,所以打印之后是看不到的。

哪位有缘的大佬看到给个答案呗~

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值