在C语言中,可以使用atoi函数将char类型转换为int类型。atoi函数将输入的字符串参数转换为相应的整数值。
以下是一个示例代码:
#include <stdio.h>
#include <stdlib.h>
int main() {
char ch = '5';
int num = atoi(&ch);
printf("The converted integer is: %d\n", num);
return 0;
}
输出结果为:The converted integer is: 5。
请注意,atoi函数只能将一个字符转换为一个整数值。如果要将一个字符串转换为整数值,可以直接传递字符串作为参数,例如:int num = atoi("123");。