您的位置:首页 > 其它

整数转换成字符串的程序--不太成熟

2007-07-25 19:00 441 查看
#include < iostream.h >
#include < math.h >
int CountItg( int ) ;
bool Con2String( int  , char * , int ) ;
void main()
{
 char s[80] ;
 int itg = 1 , i = 0 , nCount = 0 ;
 while( itg != 0 )
 {
  cout << "/ninput '0' can out of circle" << endl ;
  cout << " /nplease input the integer: "  ;
  cin >> itg ;
 
  nCount = CountItg( itg ) ;

  if( Con2String( itg  , s , nCount ) )
   cout << s << endl ;
 } 

}
int CountItg( int input )
{
 int n = 0 ;
 
 if ( input > 65535 ) return 0 ;

 while( input / 10 != 0 )
 {
  if( n > 5 ) break ;
  n ++ ;
  input = input / 10  ;
  
 }
 
 return n + 1 ;
}
bool Con2String( int input , char *s , int nCount )
{
 if( nCount == 0 ) 
 {
  cout << "please input the illegle data" << endl ;
  return false ;

 }

 int ntc = nCount ;
 int nti = input ;
 int i = 0 ;
 char tc ;
 s[ nCount ] = '/0' ; //add end flag at the end of the string
 while( nCount-- != 0 )
 {
  int nt = nti % 10 ;
  tc = nt + 48 ;
  s[ nCount ] = tc ;
  nti = nti / 10 ;
  cout << "in function Con2String" << endl ;
 }
 
 return true ;

}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息