将char型转为float型
将char型转为float型char b;
float a;
a=atof(b);
这样可以吗?
[[it] 本帖最后由 sdvethen 于 2008-9-4 17:17 编辑 [/it]]
功 能: 把字符串转换成浮点数
用 法: double atof(const char *nptr);
所以不应该将一个字符变量当参数吧. #include <stdlib.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
char b='2',*temp;
float a;
temp=&b;
a = atof(temp);
printf("%f",a);
return 0;
} a = atof((char *)&b); LS:你想程序崩溃么?
char想转float?
char c='2';
float f=c-'0';
页:
[1]
