/*
不用库函数,用C语言实现将一整型数字转化为字符串
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <assert.h>
using namespace std;
char *inverse(int num,char *str2)
{
int i = 0;
int str1[100];
while (num) //倒叙存放
{
str1[i++] = num % 10 + 48;
num = num / 10;
}
str1[i] = '\0';
for (int j = i-1; j >= 0; j--)
{
*str2++ = str1[j];
}
*str2 = '\0';
return str2;
}
int main()
{
char *p = NULL;
p = (char*)malloc(4 * 100);
int num = 12345789;
inverse(num,p);
cout << p << endl;
system("pause");
return 0;
}
C/C++ | 22-10 不用库函数,用C语言实现将一整型数字转化为字符串
最新推荐文章于 2021-05-17 15:34:04 发布