Convert double value to a char array in C

后端 未结 6 702
陌清茗
陌清茗 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:18

    If what you are asking is how to find out what bytes make up the double value in memory, try this:

    double a=2.132;
    double darr[1] = { a };
    char *arr = (char*) darr;
    

    although you probably want unsigned char, not char

提交回复
热议问题