/***
* Atox. C-atoi and atol Conversion
*
* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
*
* Purpose:
* Converts a character string into an int or long.
*
**************************************** ***************************************/
# Include <cruntime. h>
# Include <stdlib. h>
# Include <ctype. h>
/***
* Long atol (char * nptr)-convert string to long
*
* Purpose:
* Converts ASCII string pointed to by nptr to binary.
* Overflow is not detected.
*
* Entry:
* Nptr = PTR to string to convert
*
* Exit:
* Return long int value of the string
*
* Exceptions:
* None-overflow is not detected.
*
**************************************** ***************************************/
Long _ cdecl atol (
Const char * nptr
)
{
Int C;/* current char */
Long total;/* current total */
Int sign;/* If ''-'', then negative, otherwise positive */
/* Skip whitespace */
While (isspace (INT) (unsigned char) * nptr ))
++ Nptr;
C = (INT) (unsigned char) * nptr ++;
Sign = C;/* save sign indication */
If (C = ''-'' | C = ''+ '')
C = (INT) (unsigned char) * nptr ++;/* Skip sign */
Total = 0;
While (isdigit (c )){
Total = 10 * Total + (c-'0');/* accumulate digit */
C = (INT) (unsigned char) * nptr ++;/* Get next char */
}
If (Sign = ''-'')
Return-total;
Else
Return total;/* return result, negated if necessary */
}
/***
* Int atoi (char * nptr)-convert string to long
*
* Purpose:
* Converts ASCII string pointed to by nptr to binary.
* Overflow is not detected. Because of this, we can just use
* Atol ().
*
* Entry:
* Nptr = PTR to string to convert
*
* Exit:
* Return int value of the string
*
* Exceptions:
* None-overflow is not detected.
*
**************************************** ***************************************/
Int _ cdecl atoi (
Const char * nptr
)
{
Return (INT) atol (nptr );
}
# Ifndef _ no_int64
_ Int64 _ cdecl _ atoi64 (
Const char * nptr
)
{
Int C;/* current char */
_ Int64 total;/* current total */
Int sign;/* If ''-'', then negative, otherwise positive */
/* Skip whitespace */
While (isspace (INT) (unsigned char) * nptr ))
++ Nptr;
C = (INT) (unsigned char) * nptr ++;
Sign = C;/* save sign indication */
If (C = ''-'' | C = ''+ '')
C = (INT) (unsigned char) * nptr ++;/* Skip sign */
Total = 0;
While (isdigit (c )){
Total = 10 * Total + (c-'0');/* accumulate digit */
C = (INT) (unsigned char) * nptr ++;/* Get next char */
}
If (Sign = ''-'')
Return-total;
Else
Return total;/* return result, negated if necessary */
}
# Endif/* _ no_int64 */
# Include <msvcrt/errno. h>
# Include <msvcrt/stdlib. h>
# Include <msvcrt/Internal/file. h>
Char * _ ITOA (INT value, char * string, int Radix)
{
Char TMP [33];
Char * TP = TMP;
Int I;
Unsigned V;
Int sign;
Char * sp;
If (Radix> 36 | Radix <= 1)
{
_ Set_errno (Edom );
Return 0;
}
Sign = (Radix = 10 & value <0 );
If (sign)
V =-value;
Else
V = (unsigned) value;
While (v | TP = TMP)
{
I = V % Radix;
V = V/Radix;
If (I <10)
* TP ++ = I + ''0 '';
Else
* TP ++ = I + ''a'-10;
}
If (string = 0)
String = (char *) malloc (TP-TMP) + sign + 1 );
SP = string;
If (sign)
* SP ++ = ''-'';
While (TP> TMP)
* SP ++ = * -- TP;
* Sp = 0;
Return string;
}