-------------------------------------
典型例题 22:C问题---itostr() 实现。
-------------------------------------
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 void itoa( int i,char* string)
5 {
6 int power, j;
7 if(i<0)
8 {
9 i = -i;
10 *string++ = '-';
11 }
12 j=i;
13 for (power=1;j>=10;j/=10)
14 power*=10;
15 for (;power>0;power/=10)
16 {
17 *string++='0'+i/power; i%=power;
18 }
19 *string='/0';
20 }
21
22 void itostr(int value,char *str)
23 {
24 sprintf(str, "%d",value );
25 return;
26 }
27 int main()
28 {
29 int n;
30 char str[13];
31 printf("Please input the int num:/n");
32 scanf("%d",&n);
33 itostr(n,str);
34 printf("(1)int to string :%s/n",str);
35 itoa(n,str);
36 printf("(2)int to string :%s/n",str);
37 return 0;
38 }
C问题---itostr() 实现
最新推荐文章于 2025-01-03 10:38:16 发布