c语言 字符串转化
基础 这些函数都在表头文件 #include<stdlib.h>中 方法 atof(将字符串转换成浮点型数) double atof(const char *nptr) 将字符串转换为浮点数 strtod(将字符串转换成浮点数) 定义函数 double strtod(const char *nptr,char **endptr); # include <stdlib.h> # include <stdio.h> main ( ) { char * a = " 100.23" ; float b = atof ( a ) ; printf ( "a = %.2f\n" , b ) ; system ( "pause" ) ; } atoi将字符串转换成整型数 定义函数 int atoi(const char *nptr); # include <stdlib.h> # include <stdio.h> main ( ) { char a [ ] = " - 100" ; int c = atoi ( a ) ; printf ( "c = %d\n" , c ) ; system ( "pause" ) ; } atol(将字符串转换成长整型数) 定义函数 long atol(const char *nptr); strtol(将字符串转换成长整型数) 定义函数 long int