CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

求教!怎样将整型转换成字符型并输出还是那个数字??在线等待高手指教。

楼主harryho(基路亚)2003-02-01 20:11:22 在 C/C++ / C语言 提问

怎样将整型转换成字符型并输出还是那个数字?? 问题点数:20、回复次数:18Top

1 楼harryho(基路亚)回复于 2003-02-01 20:13:03 得分 0

怎样将整型转换成字符型并输出还是那个数字??是用TC++编译的.Top

2 楼red_free(酒肉穿肠过,脂肪腰间留)回复于 2003-02-01 20:14:29 得分 0

printf("%c",a+30);假设a是一个1位的整形变量.Top

3 楼micropentium6(小笨|曾经的美好)回复于 2003-02-01 20:20:01 得分 5

char   *_ecvt(   double   value,   int   count,   int   *dec,   int   *sign   );  
   
  Converts   a   double   number   to   a   string  
   
   
  #include   <stdlib.h>  
  #include   <stdio.h>  
   
  void   main(   void   )  
  {  
        int           decimal,       sign;  
        char         *buffer;  
        int           precision   =   10;  
        double     source   =   3.1415926535;  
   
        buffer   =   _ecvt(   source,   precision,   &decimal,   &sign   );  
        printf(   "source:   %2.10f       buffer:   '%s'     decimal:   %d     sign:   %d\n",  
                        source,   buffer,   decimal,   sign   );  
  }  
   
   
  Output  
   
  source:   3.1415926535       buffer:   '3141592654'     decimal:   1       sign:   0  
   
   
   
  char   *_fcvt(   double   value,   int   count,   int   *dec,   int   *sign   );  
   
  Converts   a   floating-point   number   to   a   string  
   
  #include   <stdlib.h>  
  #include   <stdio.h>  
   
  void   main(   void   )  
  {  
        int     decimal,   sign;  
        char   *buffer;  
        double   source   =   3.1415926535;  
   
        buffer   =   _fcvt(   source,   7,   &decimal,   &sign   );  
        printf(   "source:   %2.10f       buffer:   '%s'       decimal:   %d       sign:   %d\n",  
                          source,   buffer,   decimal,   sign   );  
  }  
   
   
  Output  
   
  source:   3.1415926535       buffer:   '31415927'       decimal:   1       sign:   0  
     
   
  Top

4 楼micropentium6(小笨|曾经的美好)回复于 2003-02-01 20:21:04 得分 0

#include   <cstdlib>Top

5 楼harryho(基路亚)回复于 2003-02-01 20:22:52 得分 0

还是不行啊,显示是其它字符来的。  
  我是这样测试的。void   main(){  
  int   a=30;  
  printf("%c",a+30);  
  }  
  显示是一个大于号.Top

6 楼danmao(愤怒的小mao)回复于 2003-02-01 20:29:14 得分 6

#include   <stdlib.h>  
  #include   <stdio.h>  
   
  void   main(   void   )  
  {  
        int           decimal,       sign;  
        char         *buffer;  
        int           precision   =   10;  
        double     source   =   3.1415926535;  
   
        buffer   =   _ecvt(   source,   precision,   &decimal,   &sign   );  
        printf(   "source:   %2.10f       buffer:   '%s'     decimal:   %d     sign:   %d\n",  
                        source,   buffer,   decimal,   sign   );  
  }  
   
  char   *_ecvt(    
        double   value,  
        int   count,  
        int   *dec,  
        int   *sign    
  );  
  Parameters  
  value    
  Number   to   be   converted.    
  count    
  Number   of   digits   stored.    
  dec    
  Stored   decimal-point   position.    
  sign    
  Sign   of   converted   number.    
   
  还有很多,你自己查查。  
  Top

7 楼harryho(基路亚)回复于 2003-02-01 20:30:08 得分 0

在ecvt中,其中第二,三,四个参数是什么意思??可以说得详细点吗?Top

8 楼harryho(基路亚)回复于 2003-02-01 20:31:31 得分 0

thank   you.Top

9 楼micropentium6(小笨|曾经的美好)回复于 2003-02-01 20:34:27 得分 0

去查msdn:)Top

10 楼harryho(基路亚)回复于 2003-02-01 20:46:54 得分 0

边度有MSDN下载啊??我部机无啊。Top

11 楼micropentium6(小笨|曾经的美好)回复于 2003-02-01 21:03:13 得分 0

我把它贴上来:)Top

12 楼micropentium6(小笨|曾经的美好)回复于 2003-02-01 21:06:34 得分 5

_ecvt  
  Converts   a   double   number   to   a   string.  
   
  char   *_ecvt(   double   value,   int   count,   int   *dec,   int   *sign   );  
   
  Function   Required   Header   Compatibility    
  _ecvt   <stdlib.h>   Win   95,   Win   NT    
   
   
  For   additional   compatibility   information,   see   Compatibility   in   the   Introduction.  
   
  Libraries  
   
  LIBC.LIB   Single   thread   static   library,   retail   version    
  LIBCMT.LIB   Multithread   static   library,   retail   version    
  MSVCRT.LIB   Import   library   for   MSVCRT.DLL,   retail   version    
   
   
  Return   Value  
   
  _ecvt   returns   a   pointer   to   the   string   of   digits.   There   is   no   error   return.  
   
  Parameters  
   
  value  
   
  Number   to   be   converted  
   
  count  
   
  Number   of   digits   stored  
   
  dec  
   
  Stored   decimal-point   position  
   
  sign  
   
  Sign   of   converted   number  
   
  Remarks  
   
  The   _ecvt   function   converts   a   floating-point   number   to   a   character   string.   The   value   parameter   is   the   floating-point   number   to   be   converted.   This   function   stores   up   to   count   digits   of   value   as   a   string   and   appends   a   null   character   ('\0').   If   the   number   of   digits   in   value   exceeds   count,   the   low-order   digit   is   rounded.   If   there   are   fewer   than   count   digits,   the   string   is   padded   with   zeros.  
   
  Only   digits   are   stored   in   the   string.   The   position   of   the   decimal   point   and   the   sign   of   value   can   be   obtained   from   dec   and   sign   after   the   call.   The   dec   parameter   points   to   an   integer   value   giving   the   position   of   the   decimal   point   with   respect   to   the   beginning   of   the   string.   A   0   or   negative   integer   value   indicates   that   the   decimal   point   lies   to   the   left   of   the   first   digit.   The   sign   parameter   points   to   an   integer   that   indicates   the   sign   of   the   converted   number.   If   the   integer   value   is   0,   the   number   is   positive.   Otherwise,   the   number   is   negative.  
   
  _ecvt   and   _fcvt   use   a   single   statically   allocated   buffer   for   the   conversion.   Each   call   to   one   of   these   routines   destroys   the   result   of   the   previous   call.  
  /////////////////////////////////////////////////////////////////  
   
  _fcvt  
  Converts   a   floating-point   number   to   a   string.  
   
  char   *_fcvt(   double   value,   int   count,   int   *dec,   int   *sign   );  
   
  Function   Required   Header   Compatibility    
  _fcvt   <stdlib.h>   Win   95,   Win   NT    
   
   
  For   additional   compatibility   information,   see   Compatibility   in   the   Introduction.  
   
  Libraries  
   
  LIBC.LIB   Single   thread   static   library,   retail   version    
  LIBCMT.LIB   Multithread   static   library,   retail   version    
  MSVCRT.LIB   Import   library   for   MSVCRT.DLL,   retail   version    
   
   
  Return   Value  
   
  _fcvt   returns   a   pointer   to   the   string   of   digits.   There   is   no   error   return.  
   
  Parameters  
   
  value  
   
  Number   to   be   converted  
   
  count  
   
  Number   of   digits   after   decimal   point  
   
  dec  
   
        Pointer   to   stored   decimal-point   position  
   
  sign  
   
      Pointer   to   stored   sign   indicator  
   
  Remarks  
   
  The   _fcvt   function   converts   a   floating-point   number   to   a   null-terminated   character   string.   The   value   parameter   is   the   floating-point   number   to   be   converted.   _fcvt   stores   the   digits   of   value   as   a   string   and   appends   a   null   character   ('\0').   The   count   parameter   specifies   the   number   of   digits   to   be   stored   after   the   decimal   point.   Excess   digits   are   rounded   off   to   count   places.   If   there   are   fewer   than   count   digits   of   precision,   the   string   is   padded   with   zeros.  
   
  Only   digits   are   stored   in   the   string.   The   position   of   the   decimal   point   and   the   sign   of   value   can   be   obtained   from   dec   and   sign   after   the   call.   The   dec   parameter   points   to   an   integer   value;   this   integer   value   gives   the   position   of   the   decimal   point   with   respect   to   the   beginning   of   the   string.   A   zero   or   negative   integer   value   indicates   that   the   decimal   point   lies   to   the   left   of   the   first   digit.   The   parameter   sign   points   to   an   integer   indicating   the   sign   of   value.   The   integer   is   set   to   0   if   value   is   positive   and   is   set   to   a   nonzero   number   if   value   is   negative.  
   
  _ecvt   and   _fcvt   use   a   single   statically   allocated   buffer   for   the   conversion.   Each   call   to   one   of   these   routines   destroys   the   results   of   the   previous   call.  
   
  Top

13 楼Frank001(Frank)回复于 2003-02-01 21:22:33 得分 4

可以用下面的方法试试看:  
  #include   <iostream>  
  using   namespace   std;  
   
  void   main()  
  {  
  int   a_i;  
  char   num[10];  
  cin>>a_i; //输入整形数  
  itoa(a_i,   num,   10);  
  cout<<num<<endl;  
  }Top

14 楼Frank001(Frank)回复于 2003-02-01 21:26:45 得分 0

itoa(a_i,num,10)     //a_i为要转换的整形数,num转换后的字符串数组,10表示为10进制数的转换。Top

15 楼harryho(基路亚)回复于 2003-02-01 22:16:58 得分 0

实在太谢谢你们了,令我这个刚开始对C++有兴趣的人,真正找到了C++的乐趣。祝你们新年愉快。Top

16 楼Frank001(Frank)回复于 2003-02-02 15:33:53 得分 0

呵呵,希望对你有帮助,结贴吧。  
   
  新年快乐!Top

17 楼Caoyu015(酷鱼一代)回复于 2003-02-02 16:15:17 得分 0

《C的陷阱和缺陷》   中有一段很精彩的程序。Top

18 楼fastzch(红领巾)回复于 2003-02-02 16:22:18 得分 0

这么一个简单的问题搞得大家这么大费周折,真是不可思议!  
  Top

相关问题

  • 16进制整型转换为字符
  • 如何将字符串转换成整型!------求救!
  • acces 表 SQL语句中如何转换字符型为整型
  • 整型变量于字符串变量的转换问题?
  • 怎样将字符串数字转换成整型?
  • 把整型变量转换成字符串用什么函数?
  • 有关字符串和整型数的类型转换,请教?
  • 字符变量和整型变量如何转换?
  • 一个字符串如何转换成整型?
  • 怎么将一个整型的转换为字符型 的?

关键词

  • 字符
  • 转换
  • 数字
  • source
  • decimal
  • ecvt
  • fcvt
  • sign
  • digit
  • points

得分解答快速导航

  • 帖主:harryho
  • micropentium6
  • danmao
  • micropentium6
  • Frank001

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo