home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!ieunet!!bsullivn
- From: bsullivn@sc.sni.ie (Bryan O'Sullivan)
- Newsgroups: comp.lang.c
- Subject: Re: Convert float to a string ?
- Message-ID: <167@sc.sni.ie>
- Date: 21 Aug 92 09:53:01 GMT
- Article-I.D.: sc.167
- References: <Bt91Cz.Gwv@well.sf.ca.us>
- Reply-To: bryan@sc.sni.ie
- Organization: Siemens-Nixdorf Software Development Centre, Dublin
- Lines: 19
- X-Newsreader: Tin 1.1 PL3
-
-
-
- jaked@well.sf.ca.us (Jake Donham) writes:
- >> float a = 12.34567;
- >> char b[9];
- >>
- >> sprintf(b, "%8f");
-
- >uh, make that sprintf(b, "%8f\0", a);, of course.
-
- Why? You'll overflow your array. Apart from that trivial reason, the
- '\0' you add is of no earthly use. Don't forget that string literals are
- null-terminated by default.
-
- -- Bryan
-
- --
- Bryan O'Sullivan +353-1-767551 x225
- Siemens-Nixdorf Informationssysteme AG bryan@sc.sni.ie
- Software Development Centre "Theory like mist on eyeglasses.
- Dublin Obscure facts." -- Charlie Chan
-