[Dev-C++] itoa - simple implementation [was: integer to string]
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Luigi S. <gi...@li...> - 2003-04-02 10:12:40
|
On Wed, Apr 02, 2003 at 04:38:41AM +0200, Per Westermark wrote:
> Assign of string termination will be one position off, i.e. outside your
> buffer.
> [..]
Thanks again for pointing out the bug, I'll fix it as shown by the
few code lines below.
One thing I was wondering is: since "buf" is static, may I assume
it is filled with '\0' by the compiler? (So there will be ne need
for me to place the terminating '\0')
itoa.c
------
/* .. */
/* old code: #define MAXSZ 21 */
#define MAXSZ 20 /* assuming integer is made of 19 digits + sign */
char *
itoa(int n)
{
/* old code: static char buf[MAXSZ]; */
static char buf[MAXSZ + 1];
char *p = buf + MAXSZ;
/* ... */
*p = '\0'; /* << really needed ? >> */
}
------
Regards
--
>> gisan >>
|