ex7_7.c
来自「自己做的常用库和实现的数据结构。public domain.」· C语言 代码 · 共 48 行
C
48 行
/*
ex_7_7
To change the string to the float_number.
*/
float atofloat(string)
char string[];
{
char temp ;
float result = 0 , point = 0 ;
int index = 0 , sign = 1 ;
if ( string[0] == '-' )
{
index = 1 ;
sign = -1 ;
}
while ( (temp = string[ index++ ]) != '\0' )
{
if (temp == '.')
point = 10 ;
else if (point)
{
result += (temp-'0')/point ;
point *= 10 ;
}
else
{
result = result*10 + temp-'0' ;
}
}
return ( sign*result ) ;
}
main ( )
{
char string[10];
float value ;
printf("Number :\n");
scanf ("%s",string);
value = atofloat(string);
printf("\n%f\n",value);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?