码迷,mamicode.com
首页 > 编程语言 > 详细

【算法和数据结构】_16_小算法_IntToStr: 将整型数据转换为字符串

时间:2017-06-19 12:52:40      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:char   ash   --   ons   数字   dash   code   ++   color   

 1 /*
 2  IntToStr: 将整型数据转换为字符串
 3 */
 4 
 5 #include <stdio.h>
 6 
 7 
 8 void int_to_str(const unsigned long int i_number, char *str);
 9 
10 int main(int argc,char*argv[])
11 {
12    unsigned long int i_test;
13    char str[16];
14 
15    i_test=1234567;
16    int_to_str(i_test,str);
17    
18    puts(str);
19 
20    return 0;
21 }
22 
23 /*
24 函数功能:
25          将一个整型数字转换为一个以0-9的字符组成的字符串
26          例如:
27                将 123 ——> “123”
28 函数原型:
29          void int_to_str(const unsigned long int i_number, char *str)
30 函数参数:
31          const unsigned long int i_number: 待转换的整型值
32          char *str:用来存储转换后的字符串
33 异常:
34 */
35 
36 void int_to_str(const unsigned long int i_number, char *str)
37 {
38     unsigned long int i_temp;
39     char *p_char_head;
40     char *p_char_temp;
41     char char_temp;
42     
43     i_temp=i_number;
44     p_char_head=str;
45     p_char_temp=str;
46 
47     while( 10 < i_temp )
48     {
49         *(p_char_temp++)= (i_temp % 10) + 0;
50         i_temp /= 10;
51     }
52     *(p_char_temp)=i_temp + 0;
53     *(++p_char_temp)= \0;
54     --p_char_temp;
55 
56     while(p_char_temp > p_char_head)
57     {
58         char_temp=*(p_char_temp);
59         *(p_char_temp--)=*(p_char_head);
60         *(p_char_head++)=char_temp;
61     }
62     
63 }

 

【算法和数据结构】_16_小算法_IntToStr: 将整型数据转换为字符串

标签:char   ash   --   ons   数字   dash   code   ++   color   

原文地址:http://www.cnblogs.com/volcanol/p/7047810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!