如何将uchar数组转换为字符串 [英] how to convert array of uchar to string

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

问题描述

你好


我是C的新手并且不确定如何完成以下任务:


我有以下c代码,在centos ver 3.4下,使用gnu gcc编译:


uchar sn [8];


//读数


sn [0] = 0x10;

sn [1] = 0x2E;

sn [2] = 0x22;

sn [3] = 0x47;

sn [4] = 0x00;

sn [5] = 0x08;

sn [ 6] = 0x00;

sn [7] = 0x35;


我想将上面的数组转换成Ascii字符串,有什么简单的方法吗在C中实现这一点?

最终我想做以下事情:


query ="插入测试(读取)值(sn) )" ;;

//我希望将其格式化为插入测试(读取)值('''3500080047222E10'')"

// I明白c不会插入数组''sn''的值,不像php或其他胶水语言...我希望有一些方法实现这个目标..


do_this_query(查询);


任何帮助都将不胜感激。

hello

I am new to C and not sure how to go about getting the following accomplished:

I have the following c code, under centos ver 3.4, using gnu gcc to compile:

uchar sn[8];

// readings

sn[0] = 0x10;
sn[1] = 0x2E;
sn[2] = 0x22;
sn[3] = 0x47;
sn[4] = 0x00;
sn[5] = 0x08;
sn[6] = 0x00;
sn[7] = 0x35;

I want to convert the above array into an Ascii string, is there any simple way of achieving this in C?

ultimately i want to do the following:

query = "Insert into test (reading) values(sn)";
// i want to get it formated as "Insert into test (reading) values (''3500080047222E10'')"
// I understand that c will not insert the value of the array ''sn'', unlike php or other glue languages...i am hoping there is some way to achieve this..

do_this_query(query);

any help would be appreciated.

推荐答案

任何想法,任何人???
any ideas, anyone???


您好,


您能发布完整的代码吗?


我可以从哪里得到这些值吗?

Hi,

Can you post your full code?

Can I know from where you are getting these values?

展开 | 选择 | Wrap | 行号




你能发布完整的代码吗?

Can you post your full code?



当然。


我的以下代码是di来自Dallas / Maxim'网站的rect副本,我已经尝试将Mysql c api合并到其中,所以我可以直接将测量的温度信息发送到sql表。


对于来自dallas的全源代码,请访问以下网站获取他们的sdk


http://files.dalsemi.com/auto_id/pub...inuxgnu300.zip


以下是我的黑客c代码,请记住我不是程序员,所以我对这个东西很新。对于来自Dallas的原始代码,您可能希望从上面的sdk中看到temp.c。

Sure.

My following code is a direct copy from Dallas/Maxim''s site, I have tried to incorporate the Mysql c api in it as well so I could directly send the measured temperature information to a sql table.

for the fullsource code from dallas, please visit the following site to get their sdk
:
http://files.dalsemi.com/auto_id/pub...inuxgnu300.zip

Following is my hacked c code, please bear in mind I am not a programmer, so I am pretty new to this stuff. For the original code from Dallas, you may want to see the temp.c from the above sdk.

展开 | 选择 | 换行 | 行号


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

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