C语言基础知识应用问题解决!

最近做手机切换开关机动画,一直累加,但加到第11个开关机动画的时候,发现一个问题,lk和kernel 的logo可以切换,但是动画无法切换。

查找原因:首先nvram的值肯定是写进去了的,不然logo也是无法正常切换的,问题出现在动画切换标志位的地方.

int get_logo_flag()
{
    char propVal[PROPERTY_VALUE_MAX];
    
    property_get(BOOT_LOGO_FLAG, propVal, "0");
		
    int propInt = atoi(propVal);

    XLOGD("get_logo_flag propInt = %d \n", propInt);
	
    return propInt;
}

这段代码很简单,就是获取字符串放到字符数组中,然后转化成整数。

为了防止出错,特意还写了代码验证过。

再次,问题肯定就出现在BOOT_LOGO_FLAG的property_set的时候。

        char logo_flag;
        logo_flag = '10';
        sprintf(propVal, "%c", logo_flag);
        printf("[boot_logo_updater]update logo flag = %s", propVal);
        property_set(BOOT_LOGO_FLAG, propVal);

 问题就出在这里,logo_flag是char型,如果放两个字符‘10’,肯定获取到的就是后面的0.
把logo_flag定义为字符数组就可以解决问题了。


下面是写的测试代码:

#include <stdio.h>

int main(void) {
	// your code goes here
   // char c = '10';
    char single;
    char test[2];
    char test1[100];
    int i;
    
    single = '157';
    test[0] = '0';
    test[1] = '9';
    i=atoi(test);
    
    printf("single=%c.\n",single);
    //printf("i=%d .\n",i);
    sprintf(test1,"%s",test);
   
   
   
    printf("test1=%s.\n",test1);
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值