www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/29/08:07:45

Date: Mon, 29 Mar 1999 15:05:52 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: ryan_brown AT my-dejanews DOT com
cc: djgpp AT delorie DOT com
Subject: Re: Converting between varable types
In-Reply-To: <7dlh6c$4b3$1@nnrp1.dejanews.com>
Message-ID: <Pine.SUN.3.91.990329150534.9091M-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Sun, 28 Mar 1999 ryan_brown AT my-dejanews DOT com wrote:

> How do you convert data between variables of different types?  I need to
> convert the data in a float variable to a char variable.  In pascal you could
> just use funcitons like FloatToStr() however in c I can't find anything.

This isn't ``conversion to a char'', this is generation of a printable
text representation of a float number.  The way it is done in C is
with the `sprintf' function.  It takes an address of a char buffer, a
format specifier (use %f if you don't have any special requirements),
and the number, and puts the text representation into the buffer.

Another possibility is to use the `fcvt' and `gcvt' functions, but
they usually are not what you'd want.

All these functions are described in detail in the library reference
(type "info libc alpha sprintf" from the DOS prompt and read there).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019