在准备蓝桥杯的时候写了这样一段代码
switch(Seg_Disp_Mode)
{
case 0:
Seg_Buf[0] = 11;
Seg_Buf[4] = unsigned char(Temperature)/10 %10;
Seg_Buf[5] = unsigned char(Temperature)%10;
Seg_Buf[6] = unsigned int(Temperature * 100)/10 % 10;
Seg_Buf[7] = unsigned int(Temperature * 100)% 10;
Seg_Point[5] = 1;
break;
case 1:
break;
case 2:
break;
}
编译之后报错:main.c(52): error C141: syntax error near 'unsigned', expected 'sizeof'
仔细检查发现时因为C语言中数据类型转换时,需要转换的类型unsigned char、unsigned int
没有用小括号括起来
应改为:
switch(Seg_Disp_Mode)
{
case 0:
Seg_Buf[0] = 11;
Seg_Buf[4] = (unsigned char)(Temperature)/10 %10;
Seg_Buf[5] = (unsigned char)(Temperature)%10;
Seg_Buf[6] = (unsigned int)(Temperature * 100)/10 % 10;
Seg_Buf[7] = (unsigned int)(Temperature * 100)% 10;
Seg_Point[5] = 1;
break;
case 1:
break;
case 2:
break;
}
类型转换相关知识补充:
https://www.runoob.com/cprogramming/c-data-types.html