comp.lang.ada
 help / color / mirror / Atom feed
* ATOI
@ 2003-07-11  8:39 Riccardo Fulcoli
  2003-07-12  1:58 ` ATOI Robert I. Eachus
  2003-07-12  9:05 ` ATOI Preben Randhol
  0 siblings, 2 replies; 4+ messages in thread
From: Riccardo Fulcoli @ 2003-07-11  8:39 UTC (permalink / raw)


HI!
I'm having problems reguarding the input/output from files in text mode.
Exactly I would like to read a field as a string of 50 characters(and for
that i'm using the redirection of the input) and after that to convert it in
a number (an integer).
i.e. I'm looking for a function like the C "atoi".
Of course I already know that the content of the field is a numeric one but
the unchecked conversions seems not to be good at the purpose.
Is there someone that could help me???
Thanks ;)

Riccardo





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

* Re: ATOI
  2003-07-11  8:39 ATOI Riccardo Fulcoli
@ 2003-07-12  1:58 ` Robert I. Eachus
  2003-07-14  1:49   ` ATOI Richard Riehle
  2003-07-12  9:05 ` ATOI Preben Randhol
  1 sibling, 1 reply; 4+ messages in thread
From: Robert I. Eachus @ 2003-07-12  1:58 UTC (permalink / raw)


Riccardo Fulcoli wrote:
> HI!
> I'm having problems reguarding the input/output from files in text mode.
> Exactly I would like to read a field as a string of 50 characters(and for
> that i'm using the redirection of the input) and after that to convert it in
> a number (an integer).
> i.e. I'm looking for a function like the C "atoi".
> Of course I already know that the content of the field is a numeric one but
> the unchecked conversions seems not to be good at the purpose.
> Is there someone that could help me???
> Thanks ;)
> 
> Riccardo

Why would you want to do an Unchecked_Conversion.  See Ada.Text_IO, or 
Ada.Integer_Text_IO.  But if you have already read in a string you can 
use the attribute function Integer'Value(Some_String).  Note that the 
function will ignore leading and trailing spaces, but otherwise can 
raise an exception which may not be what you want.  See RM 3.5(52)


-- 

                                                        Robert I. Eachus

�In an ally, considerations of house, clan, planet, race are 
insignificant beside two prime questions, which are: 1. Can he shoot? 2. 
Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and 
Steve Miller.




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

* Re: ATOI
  2003-07-11  8:39 ATOI Riccardo Fulcoli
  2003-07-12  1:58 ` ATOI Robert I. Eachus
@ 2003-07-12  9:05 ` Preben Randhol
  1 sibling, 0 replies; 4+ messages in thread
From: Preben Randhol @ 2003-07-12  9:05 UTC (permalink / raw)


Riccardo Fulcoli wrote:
> HI!
> I'm having problems reguarding the input/output from files in text mode.
> Exactly I would like to read a field as a string of 50 characters(and for
> that i'm using the redirection of the input) and after that to convert it in
> a number (an integer).
> i.e. I'm looking for a function like the C "atoi".

Number : Integer := 0;
Read_String : String (1..50);

-- Reading in the string etc...

   Number := Integer'Value (Read_String);

If I understand your question correctly

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



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

* Re: ATOI
  2003-07-12  1:58 ` ATOI Robert I. Eachus
@ 2003-07-14  1:49   ` Richard Riehle
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Riehle @ 2003-07-14  1:49 UTC (permalink / raw)


"Robert I. Eachus" wrote:

> Riccardo Fulcoli wrote:
> >
> > i.e. I'm looking for a function like the C "atoi".
> >
> Why would you want to do an Unchecked_Conversion.  See Ada.Text_IO, or
> Ada.Integer_Text_IO.  But if you have already read in a string you can
> use the attribute function Integer'Value(Some_String).  Note that the
> function will ignore leading and trailing spaces, but otherwise can
> raise an exception which may not be what you want.  See RM 3.5(52)

I recall a similar problem from a former client when someone decided
they had a need to convert the floating point of a VAX to the floating
point of a different mainframe.   A programmer was assigned to write
the algorithm to make this happen.  Those of you who know the VAX
will recall that the sign bit is in an unusual location.  The programmer
was going nuts trying to write this program until he was advised that
Text_IO.Float_IO (in Ada 83) already had a conversion routine that
would allow him to convert the floating point to scientific notation,
write it to tape, and read it with Text_IO.Float_IO on the target machine.

We so often do things the hard way when the utilities are right there
waiting to be used.

Richard Riehle




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

end of thread, other threads:[~2003-07-14  1:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-11  8:39 ATOI Riccardo Fulcoli
2003-07-12  1:58 ` ATOI Robert I. Eachus
2003-07-14  1:49   ` ATOI Richard Riehle
2003-07-12  9:05 ` ATOI Preben Randhol

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