温馨提示×

c语言字符串转int类型怎么实现

小亿
133
2024-05-30 10:06:07
栏目: 编程语言
C语言开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在C语言中,可以使用atoi()函数将字符串转换为int类型。

#include <stdio.h>
#include <stdlib.h>

int main() {
    char str[] = "12345";
    int num = atoi(str);

    printf("The converted integer is: %d\n", num);

    return 0;
}

在上面的示例中,我们将字符串"12345"转换为整数,并将结果存储在变量num中。然后我们打印出转换后的整数值。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:c语言int转字符串怎么实现

0