home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!uwm.edu!rutgers!mcdhup!pdnfido!erik
- From: erik@pdnfido.fidonet.org (Erik VanRiper)
- Newsgroups: comp.lang.c
- Subject: Re: Convert float to a string ?
- Message-ID: <1992Aug23.021013.2772@pdnfido.fidonet.org>
- Date: 23 Aug 92 02:10:13 GMT
- References: <1992Aug20.172112.1564@tin.monsanto.com> <1992Aug20.225133.12163@overload.lbl.gov> <chupchup.714358437@piggy>
- Sender: erik@pdnfido.fidonet.org
- Followup-To: poster
- Organization: The Source for Source Pub Access Unix
- Lines: 49
-
- In article <chupchup.714358437@piggy> chupchup@ferkel.ucsb.edu (Robert Earl) writes:
- >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.
-
- Just to make an already dull conversation duller <grin>... In the example
- above, (sprintf(b,"%f\0",a);), it does not matter if the \0 is after the %f,
- in the case of your argument above. You could still manage to pass it a non-
- null terminated string, and it will happily barf all over the place. If I
- remember correctly, things are evaluated left to right, so the string will
- attempt to be placed into b, then terminated with the \0. If the string
- being passed (a) is not null-terminated, the the \0 within the quotes becomes
- a waste of space, so to speak. :-)
-
- I think we are arguing the same side here, but I figured I would stick in my
- 2 cents to clear things up in my own demented way.
-
- Enjoy the rest of your weekend.
-
-
-
-
- --
- Like wow... This be a .sig, eh?
- GEEKS Anonymous - Join today!
- The Source for Source - Pub Access Unix. (516) 968-7824 or (516) 666-5877
-