comp.lang.ada
 help / color / mirror / Atom feed
* Convert ASCII numerals to Integer numbers
@ 2001-08-05 16:58 Stewart
  2001-08-05 17:34 ` Jacob Sparre Andersen
  2001-08-06 16:09 ` Adrian Knoth
  0 siblings, 2 replies; 6+ messages in thread
From: Stewart @ 2001-08-05 16:58 UTC (permalink / raw)


HI,

Gnat 3.13 on win98 and linux.

I am creating a menu and I am grabbing the terminal input using
get_line, but on this particular command the last 1 .. 3 characters
can be numerals in the range of 1 .. 999.

I am considering character'pos but how can I manipulate to an integer?

Extracted from menu:

The commands work as I require them including error handling.
If I dont use get_line I can get the integers but I cant resolve the
error handling.

 elsif Input(1..4) = Link and  19 < Max_Size and Max_Size < 23 then
         Nodea := Input(6..11); Nodeb := Input(13..18);
         Edget := Input(20..22);
         Put("The command is : "); Put(Input(1..4)); New_Line;
         Put("Node A is : "); Put(Nodea); New_Line;
         Put("Node B is : "); Put(Nodeb); New_Line;
         Put("Cost is : ");   Put(Edget); New_Line;

         Int_Range := Max_Size - 19;
         Put("Cost range is : "); Put(Int_Range); New_Line;


I now want to get the last three characters and convert them to
integers




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

* Re: Convert ASCII numerals to Integer numbers
  2001-08-05 16:58 Convert ASCII numerals to Integer numbers Stewart
@ 2001-08-05 17:34 ` Jacob Sparre Andersen
  2001-08-05 17:57   ` Stewart
  2001-08-06 16:09 ` Adrian Knoth
  1 sibling, 1 reply; 6+ messages in thread
From: Jacob Sparre Andersen @ 2001-08-05 17:34 UTC (permalink / raw)


Stewart:

> I now want to get the last three characters and convert them to
> integers

To integers as in the character position in the ASCII
(ISO-646) code table? Or to integers as in mapping '0' to 0,
'1' to '1', etc.?

I think Character'Pos will solve the first problem for you.
The second problem could for example be handled with a
character indexed array.

Jacob
-- 
"Unix, Perl og Ole har man for at slippe for at g�re
 arbejdet selv."



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

* Re: Convert ASCII numerals to Integer numbers
  2001-08-05 17:34 ` Jacob Sparre Andersen
@ 2001-08-05 17:57   ` Stewart
  2001-08-05 18:13     ` martin.m.dowie
  2001-08-05 18:15     ` tmoran
  0 siblings, 2 replies; 6+ messages in thread
From: Stewart @ 2001-08-05 17:57 UTC (permalink / raw)


On Sun, 05 Aug 2001 19:34:43 +0200, Jacob Sparre Andersen
<sparre@nbi.dk> wrote:

>Stewart:
>
>> I now want to get the last three characters and convert them to
>> integers
>
>To integers as in the character position in the ASCII
>(ISO-646) code table? Or to integers as in mapping '0' to 0,
>'1' to '1', etc.?

The second I think.

the text input looks like:
link asdf12 asdf23 25

I pickup the 25 as text and I want to be able to place the 25 as an
integer in a variable to pass to a linked list.

Stewart



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

* Re: Convert ASCII numerals to Integer numbers
  2001-08-05 17:57   ` Stewart
@ 2001-08-05 18:13     ` martin.m.dowie
  2001-08-05 18:15     ` tmoran
  1 sibling, 0 replies; 6+ messages in thread
From: martin.m.dowie @ 2001-08-05 18:13 UTC (permalink / raw)


"Stewart" <s_aitken@lineone.net> wrote in message
news:o12rmtgicuk8gav9qo7u4o5p432l58a2h9@4ax.com...
[snip]
>
> I pickup the 25 as text and I want to be able to place the 25 as an
> integer in a variable to pass to a linked list.

Have a look the 'Value attribute in Annex K of the LRM







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

* Re: Convert ASCII numerals to Integer numbers
  2001-08-05 17:57   ` Stewart
  2001-08-05 18:13     ` martin.m.dowie
@ 2001-08-05 18:15     ` tmoran
  1 sibling, 0 replies; 6+ messages in thread
From: tmoran @ 2001-08-05 18:15 UTC (permalink / raw)


>link asdf12 asdf23 25
>
>I pickup the 25 as text and I want to be able to place the 25 as an
>integer in a variable to pass to a linked list.
  v := integer'value(input(last-1 .. last));
or use ada.text_io.integer_io to read from the string.
You may want to check first that they are really digits, and the number
isn't too big to fit in an integer, etc.  Or at least expect the exception
when the input is screwed up.



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

* Re: Convert ASCII numerals to Integer numbers
  2001-08-05 16:58 Convert ASCII numerals to Integer numbers Stewart
  2001-08-05 17:34 ` Jacob Sparre Andersen
@ 2001-08-06 16:09 ` Adrian Knoth
  1 sibling, 0 replies; 6+ messages in thread
From: Adrian Knoth @ 2001-08-06 16:09 UTC (permalink / raw)


Stewart <s_aitken@lineone.net> wrote:

> I am creating a menu and I am grabbing the terminal input using
> get_line, but on this particular command the last 1 .. 3 characters
> can be numerals in the range of 1 .. 999.
> I am considering character'pos but how can I manipulate to an integer?

Generally, you can use the string index:

procedure karl is
        input : string(1..6);
        i,j : integer;
begin
        get_line(input,j);
        i := Integer'Value(input(j-2..j) );
        put(i);
end karl;

Of course, you should replace this by dynamic handling, i.e. unbounded
strings combined with input'last-2 .. input'last.

-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Microsoft - Is that a kind of toilet paper?



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

end of thread, other threads:[~2001-08-06 16:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-05 16:58 Convert ASCII numerals to Integer numbers Stewart
2001-08-05 17:34 ` Jacob Sparre Andersen
2001-08-05 17:57   ` Stewart
2001-08-05 18:13     ` martin.m.dowie
2001-08-05 18:15     ` tmoran
2001-08-06 16:09 ` Adrian Knoth

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