一、c 语言中字符数组和数字的相互转换函数;
相关函数:atof atoi,atol,
strtod,strtol,strtoul
在头文件stdlib中 #include
(1)atof(将字串转换成浮点型数)ascii to floating 的缩写
char *str = "123.456E2";
double f=atof(str);
printf("string = %s double = %lf\n", str, f);
//输出结果为:string = 123.456e2 double = 12345.600000 (2)
atoi
(将字串转换成型数) ascii to integer
char *str = "123456789";
int f=atoi(str);
printf("string = %s integer = %d\n", str, f);
//输出结果为:string = 123456789 integer = 123456789 (3)
atol
(将字串转换成长型数) ascii to long int
和上面的一组功能一样,头文件也相同,只是增添了一个遇到不合条件而终止的指针;
就是一遇到不符合条件的字符,就停止转换,将失败位置的地址放到 endptr 的地址里
(1)strtod(将字符串转成double) string to double
cha