From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,341ea6d4f1d28719 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 28 Feb 2005 21:07:41 -0600 From: "Steve" Newsgroups: comp.lang.ada References: <1109606915.447479.184780@l41g2000cwc.googlegroups.com> Subject: Re: need a little string hint... Date: Mon, 28 Feb 2005 19:07:52 -0800 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: NNTP-Posting-Host: 24.22.63.157 X-Trace: sv3-PmF0yI/KFajB84emczFjdFiU52zIrdMYEGrVfwtVqTUmDWnz2inbCQd1Or/2RTpU9Zk6A6PmthG8i8G!JzYEBF9jUf5KPFw29SAHOA2R9GH6sJZnU+SosNCSBl9kdUiSXqhMj8FDIktW X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:8551 Date: 2005-02-28T19:07:52-08:00 List-Id: In Ada a "String" is just an array of characters. The length of the string is given when the string is declared, as in: Host : String (1 .. 20) := (others => ' '); When the call Get_Host_By_Name ("localhost") is used the string is implicitly declared to have the length of the string "localhost". There are a number of ways of dealing with Ada's fixed length strings, the one to use depends on context and personal preference. I'll give an example: One approach is to create an unbounded string from the substring read by Get_Line: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; ... Host : Unbounded_String; ... declare inputBuffer : String( 1 .. 32 ); last : Natural; begin Ada.Text_Io.Get_Line( File => Config, Item => inputBuffer , Last => last ); Host := To_Unbounded_String( inputBuffer( 1 .. last ) ); end; ... Server.Addr := Addresses (Get_Host_By_Name (To_String( host )), 1); Another approach is to keep track of a separate "last" for each string, and then use the slice of the array directly. That is: Server.Addr := Addresses(Get_Host_By_Name( Host( 1 .. Last ) ) ); BTW: I haven't compiled the example above, but I know the basic technique works. Steve (The Duck) "mferracini" wrote in message news:1109606915.447479.184780@l41g2000cwc.googlegroups.com... >i need to read from a file "config.sys" host&port number. > but i have a problem with host... > > if i call: Get_Host_By_Name ("localhost") it work fine, > i i use the string read from the file don't work. > > an hint? > > grazie. > > ------------------------------------------------------------- > > procedure Client is > Server : Sock_Addr_Type; > Config : Ada.Text_Io.File_Type; > Host : String (1 .. 20) := (others => ' '); > Port_Value : String (1 .. 20) := (others => ' '); > Last : Natural := 0; > Port : Port_type := 0; > > begin > --Inizializza > --leggi da config > Ada.Text_Io.Open( > File => Config, > Mode => Ada.Text_Io.In_File, > Name => "config.ini"); --case sensitive? > > Ada.Text_Io.Get_Line( > File => Config, > Item => Host, > Last => Last); > > Ada.Text_Io.Get_Line( > File => Config, > Item => Port_Value, > Last => Last); > Ada.Integer_Text_Io.Get(Port_Value,natural(Port),Last); > > --open socket > Initialize(False); --true?? > Server.Addr := Addresses (Get_Host_By_Name (host), 1); > Server.Port := Port; > Ada.Text_Io.Put_Line("OK"); >