在C语言中,可以使用标准库函数atoi()来实现将字符串转换为数字的功能。atoi()函数的原型如下:
int atoi(const char *str);该函数接受一个以null结尾的字符串作为参数,然后将其转换为对应的整数值并返回。例如:
#include <stdio.h>#include <stdlib.h>int main() { char str[] = "12345"; int num = atoi(str); printf("The number is: %d\n", num); return 0;}上述代码将字符串"12345"转换为整数12345并输出。需要注意的是,如果字符串无法转换为整数,atoi()函数将返回0。


