我编写了以下代码....它应该将像"88"这样的字符串转换为double值88并打印出来
void convertType(char* value)
{
int i = 0;
char ch;
double ret = 0;
while((ch = value[i] )!= '\0')
{
ret = ret*10 +(ch - '0');
++i;
}
printf("%d",ret);//or %f..what is the control string for double?
}
//input string :88
Run Code Online (Sandbox Code Playgroud)
但它总是打印0 ...但是当我将ret的类型更改为int ...它工作正常...当类型为float或double时,它打印为零...所以为什么我得到这个模棱两可的结果?