拆分数据到字符串数组
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 float temp = 23.45f; 6 char ASCIIData[5]={0}; 7 int i,j,data; 8 for(i=0;i<5;i++) 9 { 10 ASCIIData[i] =0; 11 } 12 data = temp*100; 13 printf("1、data =%d\r\n",data); 14 ASCIIData[0] =data/1000+0x30; 15 data = data%1000; 16 printf("2、data =%d\r\n",data); 17 ASCIIData[1] = temp/100+0x30; 18 data = data%100; 19 printf("3、data =%d\r\n",data); 20 ASCIIData[2]= 0x2E; 21 ASCIIData[3] = data/10+0x30; 22 printf("4、data =%d\r\n",data); 23 ASCIIData[4] = data%10+0x30; 24 printf("5、data =%d\r\n",data); 25 for(j=0;j<5;j++) 26 { 27 printf("ASCIIData[%d]=%c\r\n",j,ASCIIData[j]); 28 } 29 system("pause"); 30 return 0; 31 }
这个程序主要是拆分数据转换为字符串型
![](https://images2018.cnblogs.com/blog/1408202/201806/1408202-20180629163157237-493079407.png)