关于c/c++数据类型转换问题

来源:百度知道 编辑:UC知道 时间:2024/05/05 15:43:31
用atoi()函数可以把常量字符串转为整型, 有什么函数可以把变量字符串转为整型的?
谢谢!好人一生平安!

int atoi(char *str)
将字符串转换成一个整数值

你从哪儿听说非要是常量字符串的?
只要是字符指针指向的字符串都可以转换
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int n;
char *str ="12345.67";
n = atoi(str);
printf("string = %s integer = %d", str, n);
return 0;
}

atoi本身就可以阿