home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / LTOA1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.8 KB  |  107 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - ltoa1.c
  3.  *
  4.  * function(s)
  5.  *        itoa      - converts an integer to a string
  6.  *        ltoa      - converts a long to a string
  7.  *        ultoa     - converts an unsigned long to a string
  8.  *-----------------------------------------------------------------------*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1987, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18.  
  19. #include <stdlib.h>
  20. #include <_printf.h>
  21.  
  22. /*-----------------------------------------------------------------------*
  23.  
  24. Name            itoa  - converts an integer to a string
  25.                 ltoa  - converts a long to a string
  26.                 ultoa - converts an unsigned long to a string
  27.  
  28. Usage           char *itoa(int value, char *strP, int radix);
  29.                 char *ltoa(long value, char *strP, int radix);
  30.                 char *ultoa(unsigned long value, char *strP, int radix);
  31.  
  32. Prototype in    stdlib.h
  33.                 _printf.h for __longtoa
  34.  
  35. Description     These functions  convert value to a  null-terminated string
  36.                 and  store the  result in  string. With  itoa, value  is an
  37.                 integer;  with ltoa  it is  a  long;  with ultoa  it is  an
  38.                 unsigned long.  __longtoa is the  internal routine used for
  39.                 all these conversions to ASCII (in longtoa.cas).
  40.  
  41.                 radix specifies the base to be used in converting value. it
  42.                 must be between  2 and 36 (inclusive). With  itoa and ltoa,
  43.                 if value is negative, and  radix is 10, the first character
  44.                 of string is  the minus sign (-). This does  not occur with
  45.                 ultoa. Also, ultoa performs no overflow checking.
  46.  
  47.                 maybeSigned is treated as a boolean. If false then value is
  48.                 treated  as unsigned  long and  no sign  will be  placed in
  49.                 *strP.
  50.  
  51.                 hexStyle  may take  the values  'a' or  'A' and  determines
  52.                 whether lower or  upper case alphabetics are used  when the
  53.                 radix is 11 or greater.
  54.  
  55.                 Note: The space  allocated for string must be  large enough
  56.                 to hold the returned  string including the terminating null
  57.                 character (\0).  itoa can return  up to 17  bytes; ltoa and
  58.                 ultoa, up to 33 bytes.
  59.  
  60. Return value    All these functions return a pointer to string. There is no
  61.                 error return.
  62.  
  63. *------------------------------------------------------------------------*/
  64. char * _CType _FARFUNC itoa(int value, char *strP, int radix)
  65. {
  66. #define dword   unsigned long
  67.  
  68.         return  __longtoa ((radix == 10) ? (long) value :
  69.                            (dword)((unsigned)value), strP, radix, 1, 'a');
  70. }
  71.  
  72.  
  73.  
  74. /*-----------------------------------------------------------------------*
  75.  
  76. Name            ultoa - converts an unsigned long to a string
  77.  
  78. Usage           char *ultoa(unsigned long value, char *string, int radix);
  79.  
  80. Prototype in    stdlib.h
  81.  
  82. Description     see itoa
  83.  
  84. *------------------------------------------------------------------------*/
  85. char * _CType _FARFUNC ultoa(unsigned long value, char *strP, int radix)
  86. {
  87.         return  __longtoa (value, strP, radix, 0, 'a');
  88. }
  89.  
  90.  
  91.  
  92. /*-----------------------------------------------------------------------*
  93.  
  94. Name            ltoa - converts a long to a string
  95.  
  96. Usage           char *ltoa(long value, char *string, int radix);
  97.  
  98. Prototype in    stdlib.h
  99.  
  100. Description     see itoa
  101.  
  102. *------------------------------------------------------------------------*/
  103. char * _CType _FARFUNC ltoa(long value, char *strP, int radix)
  104. {
  105.         return  __longtoa (value, strP, radix, (radix == 10), 'a');
  106. }
  107.