Mail Archives: djgpp/1999/03/29/08:07:45
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 -