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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.40.19 with SMTP id o19mr22753890ioo.4.1453110639366; Mon, 18 Jan 2016 01:50:39 -0800 (PST) X-Received: by 10.182.112.202 with SMTP id is10mr268596obb.7.1453110639343; Mon, 18 Jan 2016 01:50:39 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!o2no4119020iga.0!news-out.google.com!kr2ni1922igb.0!nntp.google.com!h5no6198157igh.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 18 Jan 2016 01:50:38 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=91.55.208.223; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf NNTP-Posting-Host: 91.55.208.223 References: <77e47c8b-7dcc-4e86-8f89-1f348cdf08dd@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Re-write a file in Ada From: AdaMagica Injection-Date: Mon, 18 Jan 2016 09:50:39 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:29146 Date: 2016-01-18T01:50:38-08:00 List-Id: Am Montag, 18. Januar 2016 01:22:22 UTC+1 schrieb comicf...@gmail.com: > First , I want to copy every line in a file , in a array of unbounded_Strings , to work on them later . > > The problem is that i don't want to give a specific > range at initializing . > > In fact , it size must be known according to the number of lines in the file . How about giving an upper bound of 1000 or 10_000 lines? This should be enough for most cases. > WITH Ada.Text_IO ; USE Ada.Text_IO ; > WITH Ada.Text_IO.Unbounded_IO ; USE Ada.Text_IO.Unbounded_IO ; > WITH Ada.Strings.Unbounded ; USE Ada.Strings.Unbounded ; > > Procedure main is > > this_file : File_type ; > Last_case : Natural := 0 ; -- last filled line Type T_Tableau is array (1 .. 10_000) of unbounded_string ; -- size with upper limit to the number of lines in the file. case_of_array : T_Tableau ; -- now a definite type > > Begin > > Open > (File => this_file , > Mode => In_file , > Name => "main.adb"); > > loop exit when End_Of_File ( this_file ) ; > > case_of_array( Last_case ) := Get_Line( this_file ); > > Last_case := Last_case + 1 ; > end loop ; > End main ;