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=0.7 required=5.0 tests=BAYES_00,FILL_THIS_FORM, FILL_THIS_FORM_LONG,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,44594e18f15138a7 X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: String manipulation question Date: 1996/05/01 Message-ID: <4m703q$jnh@news1.delphi.com>#1/1 X-Deja-AN: 152359212 organization: Delphi Internet Services Corporation newsgroups: comp.lang.ada Date: 1996-05-01T00:00:00+00:00 List-Id: >as I assume Direct_IO needs an exact byte count of the record >to find succesive records (makes sense). >... >type F_S_Flag is (Faculty, Student); >type User_Record is record > UName, Real_Name, Street_Address, City, State, Zip, Phone, > Added, Deleted, Exit_Status, Comments : String(1..40); > FS_Flag : F_S_Flag; >end record; > Put("User Name: "); > Get_Line(data.UName,Last); > data.Uname(Last+1..data.Uname'Last) := > User_Record_Mask.Uname(Last+1..User_Record_Mask.Uname'Last); >seems messy, but it must be done in order to maintain the constant length. >Null terminated strings would work, but isn't the implentation of it in Ada >just as messy as this? (How would you implement it?) How about: Default_User_Record : constant User_Record :=(UName | Real_Name | Street_Address | City | State | Zip | Phone | Added | Deleted | Exit_Status | Comments => (1..40=>' '), FS_Flag => Student); procedure Fetch(prompt:in string; field:in out string) is buffer:string(field'range); last:integer; begin Put(prompt); Get_Line(buffer, last); -- just fill as much of Field as was entered. Leave the rest alone. field(field'first .. last):=buffer(buffer'first .. last); -- if input was as long or longer than buffer, skip to next line if last = buffer'last then Skip_Line;end if; end Fetch; and data:=Default_User_Record; -- initialize all fields with defaults Fetch("User Name: ", data.UName); Fetch("Real Name: ", data.Real_Name); Fetch("Street Address: ", data.Street_Address); etc.