首页 > 编程知识 正文

c语音字符串转数字,robots字符数字串转数字

时间:2023-05-03 16:14:11 阅读:200995 作者:978

atoi, atol, atoll,atof

函数原型

#include <stdlib.h>int atoi(const char *nptr);long atol(const char *nptr);long long atoll(const char *nptr);double atof(const char *nptr);

例子

#include <stdio.h>#include <stdlib.h>int main(){char buf[] = "34536";//整形int a = atoi(buf);printf("a = %dn", a);//长整形long int b = atol(buf);printf("b = %ldn", b);//long long long long c = atoll(buf);printf("c = %lldn", c); //doubledouble d = atof(buf);printf("d = %lfn", d);return 0;}

注意,atof的返回值是double类型的,但是用float去接受也没错,和字符串的大小有关系。

只可以转换buf中最前面的数字,一旦出现别的字符,就无法继续识别

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。