comp.lang.ada
 help / color / mirror / Atom feed
* Writing to string
@ 2012-02-02 14:13 ldries46
  2012-02-02 14:40 ` AdaMagica
  2012-02-02 15:57 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 3+ messages in thread
From: ldries46 @ 2012-02-02 14:13 UTC (permalink / raw)


In C/C++ the possibility exists to write to a string.
Is there something like that in ADA?
I want to write several floating and fixed point parameters to a string with 
each a dedicated but different number of digits behind the decimal point.
for instance a= 4.10 b= 5.2 c=7.123
In C/C++ it can be done by sprintf("a= %.2f b=%.1f c=%.3f",a,b,c);
I have seen that in Ada writing to a file or a device it can also be done 
with the PUT precedure from Text-IO but I cannot find the way to use PUT for 
outputing to a string.
I possibility that crossed my mind is using the Fixed point types but 
converting the floating point values to fixed point values in a way that I 
can use a temporary type declared like:
type number is delta fix_p(after) range <>;
where fix_p is an array (0.1, 0.01, 0.001) and after is 1, 2 or 3 doesnot 
seem to work because fix_p(after) is not static.
How can I reach my objective or should I completely write it myself?

L. Dries 




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Writing to string
  2012-02-02 14:13 Writing to string ldries46
@ 2012-02-02 14:40 ` AdaMagica
  2012-02-02 15:57 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 3+ messages in thread
From: AdaMagica @ 2012-02-02 14:40 UTC (permalink / raw)


See A.10.1(55,60) for Integer_IO and Modular_IO
      procedure Put(To   : out String;
                    Item : in Num;
                    Base : in Number_Base := Default_Base);

(67) for Float_IO
      procedure Put(To   : out String;
                    Item : in Num;
                    Aft  : in Field := Default_Aft;
                    Exp  : in Field := Default_Exp);

and similarly for the other type categories.

The length of the To parameter determines, additionally to the other
parameters, the complete format of the output. See the corresponding
subchapters of chapter A.10.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Writing to string
  2012-02-02 14:13 Writing to string ldries46
  2012-02-02 14:40 ` AdaMagica
@ 2012-02-02 15:57 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry A. Kazakov @ 2012-02-02 15:57 UTC (permalink / raw)


On Thu, 2 Feb 2012 15:13:35 +0100, ldries46 wrote:

> How can I reach my objective or should I completely write it myself?

    http://www.dmitry-kazakov.de/ada/strings_edit.htm

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-02 15:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-02 14:13 Writing to string ldries46
2012-02-02 14:40 ` AdaMagica
2012-02-02 15:57 ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox