Chinaunix首页 | 论坛 | 博客
  • 博客访问: 942
  • 博文数量: 1
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-04 15:49
文章分类
文章存档

2014年(1)

我的朋友
最近访客

分类: C/C++

2014-03-04 15:50:07

#include
using namespace std;
#include

int main()
{
  int num=12345,j=0,i=0;
  char temp[7],str[7];
 
  while(num)
  {
    temp[i]=num%10+'0';
 i++;
 num=num/10;
  }
  temp[i]=0;
  printf("temp=%s\n",temp);
  i=i-1;
  printf("temp=%d\n",i);

  while(i>=0)
  {
    str[j]=temp[i];
 j++;
 i--;
  }
  str[j]=0;
  printf("string=%s\n",str);
  return 0;
}

/*********************************************************************************************************************************

C语言提供了几个标准库函数,可以将任意类型(整型、长整型、浮点型等)的数字转换为字符串。以下是用itoa()函数将整数转 换为字符串的一个例子:

    # include
    # include

    void main (void)
    {
    int num = 100;
    char str[25];
    itoa(num, str, 10);
    printf(\"The number ’num’ is %d and the string ’str’ is %s. " ,
    num, str);
    }

    itoa()函数有3个参数:第一个参数是要转换的数字,第二个参数是要写入转换结果的目标字符串,第三个参数是转移数字时所用 的基数。在上例中,转换基数为10。10:十进制;2:二进制...

阅读(150) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~