comp.lang.ada
 help / color / mirror / Atom feed
From: John English <je@brighton.ac.uk>
Subject: Re: How to convert characters in a string into integers ?
Date: Tue, 12 Feb 2002 12:03:21 +0000
Date: 2002-02-12T12:02:09+00:00	[thread overview]
Message-ID: <3C690489.2DC6927F@brighton.ac.uk> (raw)
In-Reply-To: a3hng6$jpp$1@paris.btinternet.com

Jim wrote:
> 
> is this possible, if so how ?
> 
> say im reading a string (1 + 2 + 3)    (yep carrying on with my calculator
> program :-))
> 
> how to get 1 and the convert to integer, then get + and store as character,
> get 2 and convert to integer etc ?

One way is described in section 13.3 of the textbook you're using:
you use Ada.Text_IO.Look_Ahead to see if the character you're about
to read is a digit, and if it is use Ada.Integer_Text_IO.Get to read
an integer.

Another way is to convert this pseudocode to Ada:
  result = 0
  while (next char is a digit) loop
    result = result * 10 + (value of digit char)
  end loop

There are other ways than these, too...

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



  parent reply	other threads:[~2002-02-12 12:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-02 21:59 How to convert characters in a string into integers ? Jim
2002-02-02 22:09 ` Florian Weimer
2002-02-02 23:27 ` Michal Nowak
2002-02-02 23:57   ` Jim
2002-02-03  3:25     ` Jim Rogers
2002-02-03  8:56     ` Michal Nowak
2002-02-04 16:12       ` Marin David Condic
2002-02-05  1:40         ` ARM (was: Re: How to convert characters in a string into integers ?) Jeffrey Carter
2002-02-05 14:57           ` Marin David Condic
2002-02-06 15:19             ` Ted Dennison
2002-02-06 15:52             ` Stephen Leake
2002-02-06 16:13             ` Jeffrey Carter
2002-02-10 16:47           ` Florian Weimer
2002-02-10 17:24             ` ARM (was: Re: How to convert characters in a string intointegers ?) Uckfay Ouyay
2002-02-05 14:36         ` How to convert characters in a string into integers ? Michal Nowak
2002-02-05 15:17           ` Jerry Petrey
2002-02-05 16:06             ` Marin David Condic
2002-02-14 19:52               ` ARM vs. LRM vs. ... (was: Re: How to convert characters in a string into integers ?) Tucker Taft
2002-02-14 20:12                 ` Jerry Petrey
2002-02-15  9:56                   ` Steffen Huber
2002-02-12 12:03 ` John English [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-02-06  6:55 How to convert characters in a string into integers ? Christoph Grein
2002-02-06  9:20 ` Jean-Etienne Doucet
2002-02-06 10:01 Christoph Grein
replies disabled

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