Convert double value to a char array in C

后端 未结 6 705
陌清茗
陌清茗 2021-01-05 02:36

How do I convert double value to a char array in C?

double a=2.132;
char arr[8];

Is there any way to do this in standard C? Can anyone give

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 03:08

    If you are about to store the double DATA, not the readable representation, then:

    #include 
    
    double a=2.132;
    char arr[sizeof(a)];
    memcpy(arr,&a,sizeof(a));
    

提交回复
热议问题