home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!ferkel.ucsb.edu!piggy!chupchup
- From: chupchup@ferkel.ucsb.edu (Robert Earl)
- Subject: Re: Convert float to a string ?
- Message-ID: <chupchup.714358437@piggy>
- Organization: (EVIL!)
- References: <1992Aug19.212749.21008@overload.lbl.gov> <1992Aug20.172112.1564@tin.monsanto.com> <1992Aug20.225133.12163@overload.lbl.gov>
- Date: Fri, 21 Aug 1992 00:53:57 GMT
- Lines: 33
-
- prem@prem.lbl.gov (Shirdi R. Prem) writes:
-
- | In article <1992Aug20.172112.1564@tin.monsanto.com> bcschu@skws02.monsanto.com (Brett Schultz) writes:
- | >prem@prem.lbl.gov (Shirdi R. Prem) writes:
- | >: In article <1992Aug19.204417.13500@tin.monsanto.com> bcschu@skws02.monsanto.com (Brett Schultz) writes:
- | >:
- | >: sprintf(b,"%f\0",a);
- | >: ^^^^^^
- | >:
- | >: Are you sure you need a '\0' here............???
-
- | >Let me know if sprintf puts one there anyway, I wasn't sure.
-
- | Yes. It does.
-
- No, it does NOT put one there - the '\0' is implicitly provided by the
- C compiler whenever you mention a "..." double-quoted string. sprintf
- does check for the NUL, however, when reading the format string. Once
- it reaches the NUL and copies it to the target string (in this case,
- b), it stops.
-
- If you were to somehow pass a non-NUL terminated string to sprintf, it
- would likely go off into never-never land, copying arguments and
- trying to find the zero character. But '\0' is guaranteed to
- terminate any string literal compiled into a C program, therefore the
- strings are valid input to library functions such as sprintf.
-
-
- --
- "If you've got a pig that likes jumping fences, | robert earl
- you have to make its fence a lot higher all at | rearl@ucsd.edu
- once -- if you do it by increments, all you're | rearl@piggy.ucsb.edu
- doing is training a jumping pig." -Henry Spencer|
-