在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转字符串怎么实现