怎样在c语言里把数字转成字符串?
问题同上,谢谢!#include <stdio.h>
void main()
{void convert(int n);
int number;
printf("input an integer:");
scanf("%d%,&number") ;
printf("\noutputs:");
if(number<0)
{putchar('-');
number=-number;}
convert('\n');
}
void convert(int n)
{int i;
if((i=n/10)!=0)
convert(i);
putchar((n%10)!=0);
getch();
}
这是课本给出的答案,但我运行果,得不出结果!!
题目要求用函数递归!!
[ 本帖最后由 Ja5oN 于 2007-1-5 20:19 编辑 ] itoa 函数
具体可以GOOGLE下…… 或者你可以自己写一个
原理很简单:
貌似本版曾写过
只写了atoi 从字符到数字
https://www.gdutbbs.com/viewthread.php?tid=77284&highlight=%BF%E2%BA%AF%CA%FD
[ 本帖最后由 iptton 于 2007-1-5 22:18 编辑 ] int n;
char p;
sprintf(p,"%d",n);
puts(p);
页:
[1]