Merge pull request #610 from AnthonyDiGirolamo/cpp17-compatibility

Update itoa.c for -std=c++17 compatibility
This commit is contained in:
Ha Thach authored and GitHub committed 2020-12-13 15:52:58 +07:00
commit a401e8083d
2 files changed
+59

No files matched your search

+54
View File
@@ -23,6 +23,55 @@
extern "C" {
#endif
/* reverse: reverse string s in place */
/*
static void reverse( char s[] )
{
int i, j ;
char c ;
for ( i = 0, j = strlen(s)-1 ; i < j ; i++, j-- )
{
c = s[i] ;
s[i] = s[j] ;
s[j] = c ;
}
}
*/
/* itoa: convert n to characters in s */
/*
extern void itoa( int n, char s[] )
{
int i, sign ;
if ( (sign = n) < 0 ) // record sign
{
n = -n; // make n positive
}
i = 0;
do
{ // generate digits in reverse order
s[i++] = n % 10 + '0'; // get next digit
} while ((n /= 10) > 0) ; // delete it
if (sign < 0 )
{
s[i++] = '-';
}
s[i] = '\0';
reverse( s ) ;
}
*/
extern char* itoa( int value, char *string, int radix )
{
return ltoa( value, string, radix ) ;
}
extern char* ltoa( long value, char *string, int radix )
{
char tmp[33];
@@ -73,6 +122,11 @@ extern char* ltoa( long value, char *string, int radix )
return string;
}
extern char* utoa( unsigned int value, char *string, int radix )
{
return ultoa( value, string, radix ) ;
}
extern char* ultoa( unsigned long value, char *string, int radix )
{
char tmp[33];
+5
View File
@@ -22,9 +22,14 @@
extern "C"{
#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* utoa( unsigned int value, char *string, int radix ) ;
extern char* ultoa( unsigned long value, char *string, int radix ) ;
#ifdef __cplusplus
} // extern "C"
#endif