[求助]C语言实现类型转换的问题!
怎么样把一个数字转换成字符?就像把:字符常量转换成数字一样:
int a;
char b;
a=atoi(b);
----------------解决方案--------------------------------------------------------
我也是新手,胡乱写下,很多就不考虑了。你先看看:
/*
* itos.c:
* convert decimal integer to equivalent string.
*/
#include <stdio.h>
#define MAX 20
char *itos(long long int i, char s[])
{
long long int n = 0;
unsigned ind;
char snum[] = "0123456789";
for (; i > 10; i /= 10)
n = (n + i % 10) * 10;
n += i;
for (ind = 0; n != 0; ind++, n /= 10)
s[ind] = snum[n%10];
s[ind] = '\0';
return s;
}
int main(void)
{
long long int i1 = 123456789;
char s[MAX];
printf("test...\n%s\n", itos(i1,s));
return 0;
}
----------------解决方案--------------------------------------------------------