在C中将double值转换为char数组 [英] Convert double value to a char array in C

查看:190
本文介绍了在C中将double值转换为char数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C中将double值转换为char数组?

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

double a=2.132;
char arr[8];

在标准C中有什么办法吗?任何人都可以提供任何解决方案?

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

推荐答案

如果您要存储双重DATA,而不是可读表示,那么: p>

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

#include <string.h>

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

这篇关于在C中将double值转换为char数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆