Commit 941bacc7 authored by Sandeep Mistry's avatar Sandeep Mistry

Put back ltoa and ultoa functions

parent b55555cd
...@@ -23,147 +23,93 @@ ...@@ -23,147 +23,93 @@
extern "C" { extern "C" {
#endif #endif
/* reverse: reverse string s in place */ extern char* ltoa( long value, char *string, int radix )
/*
static void reverse( char s[] )
{ {
int i, j ; char tmp[33];
char c ; char *tp = tmp;
long i;
unsigned long v;
int sign;
char *sp;
if ( string == NULL )
{
return 0 ;
}
if (radix > 36 || radix <= 1)
{
return 0 ;
}
sign = (radix == 10 && value < 0);
if (sign)
{
v = -value;
}
else
{
v = (unsigned long)value;
}
for ( i = 0, j = strlen(s)-1 ; i < j ; i++, j-- ) while (v || tp == tmp)
{ {
c = s[i] ; i = v % radix;
s[i] = s[j] ; v = v / radix;
s[j] = c ; if (i < 10)
*tp++ = i+'0';
else
*tp++ = i + 'a' - 10;
} }
sp = string;
if (sign)
*sp++ = '-';
while (tp > tmp)
*sp++ = *--tp;
*sp = 0;
return string;
} }
*/
/* itoa: convert n to characters in s */ extern char* ultoa( unsigned long value, char *string, int radix )
/*
extern void itoa( int n, char s[] )
{ {
int i, sign ; char tmp[33];
char *tp = tmp;
long i;
unsigned long v = value;
char *sp;
if ( (sign = n) < 0 ) // record sign if ( string == NULL )
{ {
n = -n; // make n positive return 0;
} }
i = 0; if (radix > 36 || radix <= 1)
do {
{ // generate digits in reverse order return 0;
s[i++] = n % 10 + '0'; // get next digit }
} while ((n /= 10) > 0) ; // delete it
if (sign < 0 ) while (v || tp == tmp)
{ {
s[i++] = '-'; i = v % radix;
v = v / radix;
if (i < 10)
*tp++ = i+'0';
else
*tp++ = i + 'a' - 10;
} }
s[i] = '\0'; sp = string;
reverse( s ) ;
}
*/
// extern char* itoa( int value, char *string, int radix ) while (tp > tmp)
// { *sp++ = *--tp;
// return ltoa( value, string, radix ) ; *sp = 0;
// }
return string;
// extern char* ltoa( long value, char *string, int radix ) }
// {
// char tmp[33];
// char *tp = tmp;
// long i;
// unsigned long v;
// int sign;
// char *sp;
// if ( string == NULL )
// {
// return 0 ;
// }
// if (radix > 36 || radix <= 1)
// {
// return 0 ;
// }
// sign = (radix == 10 && value < 0);
// if (sign)
// {
// v = -value;
// }
// else
// {
// v = (unsigned long)value;
// }
// while (v || tp == tmp)
// {
// i = v % radix;
// v = v / radix;
// if (i < 10)
// *tp++ = i+'0';
// else
// *tp++ = i + 'a' - 10;
// }
// sp = string;
// if (sign)
// *sp++ = '-';
// while (tp > tmp)
// *sp++ = *--tp;
// *sp = 0;
// return string;
// }
// // extern char* utoa( unsigned long value, char *string, int radix )
// // {
// // return ultoa( value, string, radix ) ;
// // }
// extern char* ultoa( unsigned long value, char *string, int radix )
// {
// char tmp[33];
// char *tp = tmp;
// long i;
// unsigned long v = value;
// char *sp;
// if ( string == NULL )
// {
// return 0;
// }
// if (radix > 36 || radix <= 1)
// {
// return 0;
// }
// while (v || tp == tmp)
// {
// i = v % radix;
// v = v / radix;
// if (i < 10)
// *tp++ = i+'0';
// else
// *tp++ = i + 'a' - 10;
// }
// sp = string;
// while (tp > tmp)
// *sp++ = *--tp;
// *sp = 0;
// return string;
// }
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
......
...@@ -22,11 +22,7 @@ ...@@ -22,11 +22,7 @@
extern "C"{ extern "C"{
#endif #endif
//extern void itoa( int n, char s[] ) ;
// extern char* itoa( int value, char *string, int radix ) ;
extern char* ltoa( long value, char *string, int radix ) ; extern char* ltoa( long value, char *string, int radix ) ;
// extern char* utoa( unsigned long value, char *string, int radix ) ;
extern char* ultoa( unsigned long value, char *string, int radix ) ; extern char* ultoa( unsigned long value, char *string, int radix ) ;
#ifdef __cplusplus #ifdef __cplusplus
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment