comp.lang.ada
 help / color / mirror / Atom feed
From: anon@anon.org (anon)
Subject: Re: Ada Recursion with strings
Date: Wed, 01 Oct 2008 03:01:01 GMT
Date: 2008-10-01T03:01:01+00:00	[thread overview]
Message-ID: <NJBEk.248887$102.53602@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: ff8b4b01-211b-4487-8184-85563f4148db@t42g2000hsg.googlegroups.com

If your using GNAT.

Checkout "GNAT.SOCKET.IMAGE"  in file g-socket.adb. The "Image" routine 
converts the IP address (IPv4 and IPv6) to a string. Might give you some 
Ideas.


In <ff8b4b01-211b-4487-8184-85563f4148db@t42g2000hsg.googlegroups.com>, Joe <joesmoe10@gmail.com> writes:
>Hey all,
>I'm trying to write a function that converts a 2**32 mod type into an
>string formatted like an IP address (i.e. 192.168.2.1).
>
>Here's what I wrote
>
>with Ada.Text_IO;
>use  Ada.Text_IO;
>
>procedure Ip_packet is
>   type Word_Type is mod 2**32;
>
>   function IP_String (Word : Word_Type;
>                       IP_String : String := "") return String
>is
>      Sub_String : String := Word_Type'Image(Word mod 2**8);
>   begin
>      if Word <= 2**8 then
>         return Word_Type'Image(Word) & IP_String;
>      else
>         return IP_String( Word / 2**8,
>                           "." & Sub_String & IP_String);
>      end if;
>   end IP_String;
>
>begin  --  Ip_packet
>   Put(IP_String(123456));
>end Ip_packet;
>
>There are 2 errors with this that I don't understand.  First, Ada
>expects an integer for (word / 2**8).  Is this because word_type is
>outside the standard integer range?  How do I get a division operator
>that works on word_type?
>
>If I patch the integer error by type casting word to an integer I get
>another error.  On the second return statement, Ada complains that
>there are "too many subscripts in array reference".  Is there a
>limitation on the string I can pass to a recursive function call?
>
>Thanks,
>Joe




      parent reply	other threads:[~2008-10-01  3:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-30 20:30 Ada Recursion with strings Joe
2008-09-30 22:24 ` Adam Beneschan
2008-09-30 22:24 ` Jeffrey R. Carter
2008-10-01  0:13   ` Joe
2008-10-01  0:27     ` Jeffrey R. Carter
2008-10-01  1:15       ` Robert A Duff
2008-10-01 11:34         ` Jeffrey R. Carter
2008-10-01 14:29           ` Adam Beneschan
2008-10-01 15:18             ` Jean-Pierre Rosen
2008-10-01 16:47               ` Georg Bauhaus
2008-10-02  7:24               ` Niklas Holsti
2008-10-02  8:18                 ` Ludovic Brenta
2008-10-03  6:54             ` Maciej Sobczak
2008-10-03  7:38               ` Jean-Pierre Rosen
2008-10-03  9:06               ` Dmitry A. Kazakov
2008-10-01  0:28     ` Adam Beneschan
2008-10-01  9:48       ` Georg Bauhaus
2008-10-01 10:22         ` Dmitry A. Kazakov
2008-10-01  3:01 ` anon [this message]
replies disabled

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