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.3 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5a8b3d7ed8d4ae38 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-09-25 22:40:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!fr.usenet-edu.net!usenet-edu.net!enst.fr!not-for-mail From: "Grein, Christoph" Newsgroups: comp.lang.ada Subject: Re: Problem with Get_Line Date: Thu, 26 Sep 2002 07:34:15 +0200 (MET DST) Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii X-Trace: avanie.enst.fr 1033018803 30392 137.194.161.2 (26 Sep 2002 05:40:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Thu, 26 Sep 2002 05:40:03 +0000 (UTC) Return-Path: X-Authentication-Warning: mail.eurocopter.com: uucp set sender to using -f Content-MD5: EevFIwWrlaXUGQNDK+RMjQ== X-Mailer: dtmail 1.2.1 CDE Version 1.2.1 SunOS 5.6 sun4u sparc Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.13 Precedence: bulk X-Reply-To: "Grein, Christoph" List-Unsubscribe: , List-Id: comp.lang.ada mail<->news gateway List-Post: List-Help: List-Subscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:29346 Date: 2002-09-26T07:34:15+02:00 > with Ada.Text_Io, Ada.Strings, Ada.Integer_Text_Io; > use Ada.Text_Io, Ada.Strings, Ada.Integer_Text_Io; > > procedure Agenda is > type Agenda_Record is > record > Nombre : String ( 1 .. 30 ); > Len : Integer; Len : Natural := 0; -- this is preferable > Usado : Character := 'N'; Usado: Boolean := False; -- this is preferable > end record; > > Max : constant Integer := 3; Max : constant := 3; -- this is preferable type Agenda_Index is range 0 .. Max; subtype Proper_Indes is Agenda_Index range 1 .. Agenda_Index'Last > type Agenda_Type is array(1 .. Max) of Agenda_Record; type Agenda_Type is array (Proper_Indes) of Agenda_Record; > Agenda : Agenda_Type; > Opc : Integer; Use an enumeration type for options like type Opcion is (Leer, Terminar); > > function Regresa_Libre (Agenda : in Agenda_Type) return Integer is > function Regresa_Libre (Agenda : in Agenda_Type) return Agenda_Index is > begin > for I in 1 .. Max loop for I in Agenda'Range loop -- this is preferable > if Agenda(I).Usado = 'N' then if not Agenda(I).Usado then -- this is preferable > return I; > end if; > end loop; > return 0; > end Regresa_Libre; > > procedure Lee_Nombres (Agenda : out Agenda_Type) is > Pos : Integer := 1; > Pos : Agenda_Index; > begin > Pos := Regresa_Libre(Agenda); > Flush; > Put_Line("La posicion es: "); > Put(Pos); > if Pos = 0 then > Put_Line("No hay espacio en la agenda"); > else > Put_Line("Nombre: "); > -- This Get_Line do not execute!!! > Get_Line(Agenda(Pos).nombre, Agenda(Pos).Len); > end if; > end Lee_Nombres; > > begin > loop > Put_Line("** Agenda en Ada95 **"); > Put_Line(""); > Put_Line("1. Insertar registros a la agenda"); > Put_Line("9. Salir"); > Put_Line(""); > Put("Opcion> "); > Get(Opc); case Opc is when Leer => when Terminar => end case; > exit when Opc = 9; > case Opc is > when 1 => > Lee_Nombres(Agenda); > when others => > Put_Line("Opcion Incorrecta!!!"); > end case; > > end loop; > > Lee_Nombres( Agenda ); > Put_Line("Los nombres leidos son:"); > for I in 1 .. Max loop > Put_Line(Agenda(I).Nombre); > Put(Agenda(I).Len); > end loop; > end Agenda; I've added some hints about improvement. They are not complete, e.g. error input handling is missing (what happens if a letter rather than a number is input into your program when you read options?). The problem why your Get_Line does not work is the following: When you are prompted for the option "Opcion> ", you presumably enter a number and then hit the return key. Get(Opc) just reads the number, leaving the end of line in the input stream. The your Get_Line(Agenda(Pos).nombre, Agenda(Pos).Len) finds an empty string and returns 0 in Agenda(Pos).Len. Try to enter "1 un_nombre" at the prompt and see what happens. To solve the problem, add a Skip_Line after Get(Opc).