求助!!!关于字符串指针变量,其字符对应的ASCI码的输入

[复制链接]
2727|2
 楼主| zyyly 发表于 2008-9-28 15:47 | 显示全部楼层 |阅读模式
unsigned&nbsp;char&nbsp;code&nbsp;*source_string[17]={{&quot;60.0&quot;},{&quot;58.0&quot;},{&quot;46.0&quot;},{&quot;47.0&quot;},{&quot;55.5&quot;},{&quot;55.1&quot;},{&quot;54.7&quot;},{&quot;54.3&quot;},{&quot;53.9&quot;},{&quot;53.2&quot;},<br />{&quot;46.0&quot;},{&quot;49.0&quot;},{&quot;47.5&quot;},{&quot;60.0&quot;},{&quot;20.0&quot;},{&quot;24.0&quot;},{&quot;20.0&quot;},};<br />&nbsp;&nbsp;&nbsp;long&nbsp;a;&nbsp;long*p;<br />例如:如何把“60.0”对应的ASCI码36302E30赋给a?又如何把a=36302E30对应的字符串60.0赋给*source_string[0]?谢谢!<br />
su_mj000 发表于 2008-9-28 23:56 | 显示全部楼层

使用标准库函数 atof()

但问题是,‘long’数据类型无法容纳小数部分。解决的途径方法可以是表中的常数放大10倍。<br />即60.0&nbsp;-&gt&nbsp;600;&nbsp;54.7&nbsp;-&gt&nbsp;547,...。换用标准库函数atol()。<br /><br />更简单有效的做法是:<br />code&nbsp;unsigned&nbsp;int&nbsp;source_string[17]={600,&nbsp;580,&nbsp;460,&nbsp;...};<br /><br />或:<br /><br />code&nbsp;float&nbsp;source_string[17]={60.0,&nbsp;58.0,&nbsp;46.0,&nbsp;...};
zgl7903 发表于 2008-10-3 21:04 | 显示全部楼层

使用UNION联合体结构即可

typedef&nbsp;union&nbsp;_FOURBYTE_UNION<br />{<br />&nbsp;&nbsp;unsigned&nbsp;char&nbsp;uchar_data[4];<br />&nbsp;&nbsp;long&nbsp;long_data;<br />&nbsp;&nbsp;unsigned&nbsp;long&nbsp;ulong_data;<br />}FOURBYTE_UNION;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

10

主题

10

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部