如何将BYTE字符串写为char * [英] How to write a BYTE string as a char*

查看:73
本文介绍了如何将BYTE字符串写为char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


我有这样的字节加载:


unsigned char mybyte [] = {0xa1,0x14,0x02, 0x01,0x01,0x02,0x01,0x0a,

0x30,0x0c,0x80,

0x03,0x32,0x30,0x31,0x62,0x05,0x80, 0x03,0x32,0x30,0x32};


但是我想把它们写成一个字符串。所以我试过这个:


char szSend [] =

" \ x0a1 \ x014 \ x002 \ x001 \ x001 \ x002 \ x00100 \ x00a \ x030 \ x00 \\ nc \ x080 \ x003201 \x062 \ x005 \ x

080 \ x003202" ;;


但是这给了我一个编译错误


错误C2022:''12801'':对于角色来说太大了

错误C2022:''12802 '':对于角色来说太大了

我可以不这样做吗?对于我来说,将这些非打印的b / b $ b字符放入字符串中最简单的方法是什么?或者我需要使用像sprintf这样的东西吗?

这样做吗?


Hello

I have a load of bytes like this:

unsigned char mybyte[] = {0xa1, 0x14, 0x02, 0x01, 0x01, 0x02, 0x01, 0x0a,
0x30, 0x0c, 0x80,

0x03, 0x32, 0x30, 0x31, 0x62, 0x05, 0x80, 0x03, 0x32, 0x30, 0x32};

But I want to write them as a string. so I tried this:

char szSend[] =
"\x0a1\x014\x002\x001\x001\x002\x001\x00a\x030\x00 c\x080\x003201\x062\x005\x
080\x003202";

But that gave me a compile error

error C2022: ''12801'' : too big for character
error C2022: ''12802'' : too big for character
Can I not do this? What is easiest way for me to put these non printing
characters into a string? Or will I need to use something like sprintf to
do this?


推荐答案

在文章< eo ******************* @ news.demon.co.uk> ;,

Angus< no **** @ gmail.comwrote:
In article <eo*******************@news.demon.co.uk>,
Angus <no****@gmail.comwrote:

> unsigned char mybyte [] = {0xa1,0x14,0x02,0x01,0x01,0x02,0x01,0x0a,
0x30,0x0c,0x80,
0x03,0x32,0x30,0x31,0x62,0x05,0x80,0x03,0x32,0x30,0x32};
>unsigned char mybyte[] = {0xa1, 0x14, 0x02, 0x01, 0x01, 0x02, 0x01, 0x0a,
0x30, 0x0c, 0x80,
0x03, 0x32, 0x30, 0x31, 0x62, 0x05, 0x80, 0x03, 0x32, 0x30, 0x32};


>但我想把它们写成一个字符串。所以我试过这个:

char szSend [] =
" \ x0a1 \ x014 \ x002 \ x001 \ x001 \ x002 \ x001 \ x00a \ x030 \ x0 0c \x080 \ x003201 \x062 \ x005 \ x
080 \ x003202" ;;
>But I want to write them as a string. so I tried this:

char szSend[] =
"\x0a1\x014\x002\x001\x001\x002\x001\x00a\x030\x0 0c\x080\x003201\x062\x005\x
080\x003202";



这两个应该匹配吗?在第一个你有03 32 30 31和

在第二个003201。


如果你在一个字符串上添加一个零,那么第一个字符串非常好结束。


- 理查德

-

考虑需要多达32个字符

在某些字母表中" - X3.4,1963。

Are those two supposed to match? In the first you have 03 32 30 31 and
in the second 003201.

The first is perfectly good as a string if you add a zero on the end.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.



>

我可以不这样做吗?对于我来说,将这些非打印的b / b $ b字符放入字符串中最简单的方法是什么?或者我需要使用像sprintf这样的东西吗?
这样做吗?
>
Can I not do this? What is easiest way for me to put these non printing
characters into a string? Or will I need to use something like sprintf to
do this?



您认为哪些字符是不可打印的?

Which characters do you think are non-printable?




Angus写道:

Angus wrote:

你好


我有这样的字节加载:


unsigned char mybyte [] = {0xa1,0x14,0x02,0x01,0x01,0x02,0x01,0x0a,

0x30,0x0c,0x80,

0x03,0x32,0x30,0x31,0x62,0x05,0x80,0x03,0x32,0x30,0x32};


但我想把它们写成字符串。所以我试过这个:


char szSend [] =

" \ x0a1 \ x014 \ x002 \ x001 \ x001 \ x002 \ x00100 \ x00a \ x030 \ x00 \\ nc \ x080 \ x003201 \x062 \ x005 \ x

080 \ x003202" ;;


但是这给了我一个编译错误


错误C2022:''12801'':对于角色来说太大了

错误C2022:''12802 '':对于字符来说太大了
Hello

I have a load of bytes like this:

unsigned char mybyte[] = {0xa1, 0x14, 0x02, 0x01, 0x01, 0x02, 0x01, 0x0a,
0x30, 0x0c, 0x80,

0x03, 0x32, 0x30, 0x31, 0x62, 0x05, 0x80, 0x03, 0x32, 0x30, 0x32};

But I want to write them as a string. so I tried this:

char szSend[] =
"\x0a1\x014\x002\x001\x001\x002\x001\x00a\x030\x00 c\x080\x003201\x062\x005\x
080\x003202";

But that gave me a compile error

error C2022: ''12801'' : too big for character
error C2022: ''12802'' : too big for character



你的初始化字符串包含两个十六进制常量,看起来好像是
太大而不能成为字符。 $>
\ x003201 == 12801

\ x003202 == 12802


更正这些常量,使它们各自代表可以

存储在char中,编译器将停止抱怨。


HTH

-

Lew

Your initialization string contains two hex constants that appear to be
too big to be characters.
\x003201 == 12801
\x003202 == 12802

Correct these constants so that they each represent something that can
be stored in a char, and your compiler will stop complaining.

HTH
--
Lew


这篇关于如何将BYTE字符串写为char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆