字符串转整型要用到atoi()
整形转字符串要用到_itoa_s()
同时要引入头文件stdlib.h
#include<stdio.h>
#include<stdlib.h>
int main()
{
//字符串转整型//
printf("%d\n", atoi("1234")); //会输出1234
printf("%d\n", atoi("+1234")); //会输出1234
printf("%d\n", atoi("-1234")); //会输出-1234
printf("%d\n", atoi("--1234")); //会输出0
printf("%d\n", atoi("12+34")); //会输出12
printf("%d\n", atoi("12 34")); //会输出12
printf("%d\n", atoi(" 1234"));//会输出1234
//整型转字符串//
char str[20];
_itoa_s(10, str, 20, 10);//第一个10是要转换的数,然后传到str里,str的大小是20字节,最后一个10是以10进制去存
printf("%s\n", str);
return 0;
}