Re: [Dev-C++] itoa - simple implementation [was: integer to string]
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-04-02 17:35:48
|
Yes, global variables and static variables are always zero-filled on
startup, so in this case, you could skip the terminating zero.
/Per W
On Wed, 2 Apr 2003, Luigi Santillo wrote:
> 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 >>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|