实现一个函数itoa(int n,char s[]),将整数n这个数字转换为对应的字符串,保存到s中
#include<stdio.h>
#include<stdlib.h>
void my_itoa(char arr[],int n)//数字转换为对应的字符串
{
int i = 0;
int start = 0;
int end = 0;
while (n)
{
arr[i] = (n % 10)+'0';
n = n / 10;
i++;
}
end = i - 1;
while (start < end)
{
char tmp = arr[start];
arr[start] = arr[end];
arr[end] = tmp;
start++;
end--;
}
arr[i] = '\0';
}
int main()
{
int a = 1234;
char s[10] = {0};
my_itoa(s,a);
printf("%s\n", s);
system("pause");
return 0;
}
转载于:https://blog.51cto.com/10797127/1716180