整数转换成字符串的程序--不太成熟
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 ;
}
#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 ;
}
相关文章推荐
- 8.编写一个程序,它先将键盘上输入的一个字符串转换成十进制整数
- 整数转换成16进制字符串的程序
- 关于把字符串整数转换成整数的程序
- 8、编写一个程序,它先将键盘上输入的一个字符串转换成十进制整数, 然后打印出这个十进制整数对应的二进制形式。
- 关于把字符串整数转换成整数的程序
- 今天挑战的字符串转换成整数的程序
- 利用指针完成将一个数字字符串转换为int整数的程序。
- c程序十六进制字符串转换为整数与反转
- 编写程序实现字符串到整数的转换。
- 程序员编程艺术第三十~三十一章:字符串转换成整数,通配符字符串匹配
- 【C语言】【笔试题】实现一个函数int my_atoi(char s[]),可以将一个字符串转换为对应的整数。
- 剑指offer--把字符串转换成整数
- 将一个十六进制数的字符串参数转换成整数返回
- (1411)实现字符串与整数的相互转换(不使用itoa和atoi)
- 面试题49:将字符串转换成整数
- c语言字符串整数转换
- 面试100题:20.把对应数字字符串转换成整数
- 将字符串转换为整数
- 有一个整数数组,请声明一个字符串数组,将整数数组中的每一个元素的值转换为字符串保存到字符串数组中
- 将一个字符串转换成一个整数