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,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7a042905ca129849 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-09 14:07:47 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!nntp-relay.ihug.net!ihug.co.nz!cox.net!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!870a9d88!not-for-mail From: "Eric G. Miller" Subject: Re: Record concatenation? Newsgroups: comp.lang.ada Message-ID: References: User-Agent: Pan/0.11.3 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: "devine" Date: Sun, 09 Jun 2002 21:07:41 GMT NNTP-Posting-Host: 216.119.47.131 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1023656861 216.119.47.131 (Sun, 09 Jun 2002 14:07:41 PDT) NNTP-Posting-Date: Sun, 09 Jun 2002 14:07:41 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:25625 Date: 2002-06-09T21:07:41+00:00 List-Id: In , devine wrote: > Can someone tell me how to concant records in ada? For example say you have > a record: > > TYPE Sales IS RECORD > SaleNo : Integer; > SalesmanNo : String(1..20); > END RECORD; > SalesData : Array(1..10) OF Sales; > > The data for the record is read from a file, say the file contains: > 1234 Some Name > 1234 Some Name > 1235 Someone Else > > What is the easiest way to join the first 2 records so that if you write > back to the file or display the data to the screen it displays: > 1234 Some Name > 1235 Someone Else > > I was thinking of checking if the previous number was the same as the next > number and then add the previous number to a subtotal, and if the number was > diff it would do to the next number and so on. Is thier a simpler way? You're not wanting concatenation, but elimination. Easiest way is to sort the records, then eliminate duplicates by comparing each record to its predecessor (you always keep the first record of the sorted set). If you're going to use arrays, you probably want to create an array type for your sales, so the length can be easily varied. type Sales_Array is array (Natural <>) of Sales; -- write a comparison function function "<" (Left, Right : Sales) return Boolean; -- write a sort routine (quick sort...) procedure Sort (Data : in out Sales_Array); -- function returns a Sales_Array with unique entries -- data must be in sorted order function Unique (Data : Sales_Array) return Sales_Array;