本帖最后由 and001 于 2013-8-19 11:49 编辑
存在如下一个赋值问题:
我的目的是将一个4位数分别单独转换成数字显示出来:
方法一:
char i=1;
unsigned ring_lengther[2]={2023,6723};
unsigned ring_lengther;
unsinged k2,
ring_lengther=ring_length;
k2= ring_length/1000;
k3=ring_length%1000/100;
k4=ring_length%100/10;
k5=ring_length%10;
运行最后显示的是: 0000
方法二:
char i=1;
unsigned ring_length[2]={2023,6723};
unsigned ring_lengther;
unsinged k2,
ring_lengther=ring_length;
k2= ring_lengther/1000;
k3=ring_lengther%1000/100;
k4=ring_lengther%100/10;
k5=ring_lengther%10;
运行最后显示的是:K2=6 K3=7 K4=2 K5=3
请弄过的朋友解释下为啥方法一得不到所需要的结果?!
各抒己见!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
应该为 ring_lengther=ring_length[i];
不知道为啥改不了!
一个是数组直接操作除和取余运行,一个是数组赋给一变量后进行运算!
楼下看清了吗?
什么数据类型? 应该是unsigned int ring_lengther[2]={2023,6723};
不好意思再贴一次问题(贴上去的时候是漏了东西)
再贴一次:
方法一:
unsigned char i=1;
unsigned short ring_length[2]={2023,6723};
unsigned short ring_lengther;
unsinged char k2,k3,k4,k5;
ring_lengther=ring_length;
k2= ring_length/1000;
k3=ring_length%1000/100;
k4=ring_length%100/10;
k5=ring_length%10;
运行结果: 0000
方法二:
unsigned char i=1;
unsigned short ring_length[2]={2023,6723};
unsigned short ring_lengther;
unsinged char k2,k3,k4,k5;
ring_lengther=ring_length;
k2= ring_lengther/1000;
k3=ring_lengther%1000/100;
k4=ring_lengther%100/10;
k5=ring_lengther%10;
运行结果: k2=6 k3=7 k4=2 k5=3
一周热门 更多>