home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12638 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  1.0 KB

  1. Path: sparky!uunet!mcsun!ieunet!!bsullivn
  2. From: bsullivn@sc.sni.ie (Bryan O'Sullivan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Convert float to a string ?
  5. Message-ID: <167@sc.sni.ie>
  6. Date: 21 Aug 92 09:53:01 GMT
  7. Article-I.D.: sc.167
  8. References: <Bt91Cz.Gwv@well.sf.ca.us>
  9. Reply-To: bryan@sc.sni.ie
  10. Organization: Siemens-Nixdorf Software Development Centre, Dublin
  11. Lines: 19
  12. X-Newsreader: Tin 1.1 PL3
  13.  
  14.  
  15.  
  16. jaked@well.sf.ca.us (Jake Donham) writes:
  17. >>  float a = 12.34567;
  18. >>  char b[9];
  19. >>
  20. >>  sprintf(b, "%8f");
  21.  
  22. >uh, make that sprintf(b, "%8f\0", a);, of course.
  23.  
  24. Why?  You'll overflow your array.  Apart from that trivial reason, the
  25. '\0' you add is of no earthly use.  Don't forget that string literals are
  26. null-terminated by default.
  27.  
  28.     -- Bryan
  29.  
  30. -- 
  31. Bryan O'Sullivan                                             +353-1-767551 x225
  32. Siemens-Nixdorf Informationssysteme AG                          bryan@sc.sni.ie
  33. Software Development Centre                    "Theory like mist on eyeglasses.
  34. Dublin                                          Obscure facts." -- Charlie Chan
  35.