相关疑难解决方法(0)

将ASCII字符串转换为int/float/long

我有这个代码将ASCII字符串转换为int,float或double.但是,它为所有这些打印"42".我哪里做错了?语法看起来正确,没有警告.

#include <stdlib.h>
int main(void)
{
     char *buf1 = "42";
     char buf2[] = "69.00";
     int i;
     double d;
     long l;
     i = atoi(buf1);
     l = atol(buf1);
     d = atof(buf2);
     printf("%d\t%d\t%d\n", i, l, d);
     return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1