从unsigned char中检索两个字符* [英] Retrieving two chars from unsigned char *

查看:127
本文介绍了从unsigned char中检索两个字符*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个指向32个字符的字符串的unsigned char *数据。我需要在字符串中间检索2个字符。


最好的方法是什么?

平台是嵌入式8位atmel处理器。


谢谢

解决方案

Seth写道:


我有一个无符号的char *数据,指向一个32个字符的字符串。我需要在字符串中间检索2个字符。


最好的方法是什么?

平台是嵌入式8位atmel处理器。



unsigned char * data = ...不管......;

unsigned char c1 = data [15];

unsigned char c2 = data [16];


这适用于所有处理器:Atmel,Hormel,

和Wilhelmtell。


-

Eric Sosman
es * **** @ ieee-dot-org.inva 盖子


非常感谢。

我在相关的说明中我正在比较两个unsigned char和strcmp我

get:

警告:'strcmp'的参数2中的指针目标不同

签名


我应该为此担心吗?


谢谢


7月25日,11日:25 * pm,Eri​​c Sosman< esos ... @ ieee-dot-org.invalidwrote:


Seth写道:


我有一个指向32个字符的字符串的unsigned char *数据。我需要在字符串中间检索2个字符。
需要检索2个字符。


最好的方法是什么?

平台是嵌入式8位atmel处理器。



* * * * unsigned char * data = ...等等......;

* * * * unsigned char c1 = data [15];

* * * * unsigned char c2 = data [16];


* * *这适用于所有处理器:Atmel,Hormel ,

和Wilhelmtell。


-

Eric Sosman

esos ... @ ieee -dot-org.invalid


Seth写道:


非常感谢。

在我将两个unsigned char与strcmp进行比较时的相关说明中我得到:

警告:指针指向'strcmp的参数2' ''不同

签名


我应该担心这个吗?


谢谢



如果数组仅由基本的

字符集中指定的字符组成,那么你不必担心。如果你的数组可能包含任何字节值的
,那么将无符号值解释为有符号值

可能会导致溢出和未定义的行为。


I have a unsigned char *data that points to a 32 character string. I
need to retrieve 2 characters in the middle of the string.

What is the best way to do this?
Platform is embedded 8-bit atmel processor.

Thanks

解决方案

Seth wrote:

I have a unsigned char *data that points to a 32 character string. I
need to retrieve 2 characters in the middle of the string.

What is the best way to do this?
Platform is embedded 8-bit atmel processor.

unsigned char *data = ...whatever...;
unsigned char c1 = data[15];
unsigned char c2 = data[16];

This should work on all processors: Atmel, Hormel,
and Wilhelmtell.

--
Eric Sosman
es*****@ieee-dot-org.invalid


Thanks a lot.
On a related note when I am comparing two unsigned char with strcmp I
get:
warning: pointer targets in passing argument 2 of ''strcmp'' differ in
signedness

Should I be worried about this?

Thanks

On Jul 25, 11:25*pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote:

Seth wrote:

I have a unsigned char *data that points to a 32 character string. I
need to retrieve 2 characters in the middle of the string.

What is the best way to do this?
Platform is embedded 8-bit atmel processor.


* * * * unsigned char *data = ...whatever...;
* * * * unsigned char c1 = data[15];
* * * * unsigned char c2 = data[16];

* * *This should work on all processors: Atmel, Hormel,
and Wilhelmtell.

--
Eric Sosman
esos...@ieee-dot-org.invalid


Seth wrote:

Thanks a lot.
On a related note when I am comparing two unsigned char with strcmp I
get:
warning: pointer targets in passing argument 2 of ''strcmp'' differ in
signedness

Should I be worried about this?

Thanks

If you array is composed solely of the characters specified in the basic
character set, then you needn''t be worried. If your array may consist
of any byte value then interpreting an unsigned value as a signed value
may cause overflow and undefined behaviour.


这篇关于从unsigned char中检索两个字符*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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