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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.unit0.net!cyclone03.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!peer03.am1!peering.am1!npeersf04.am4!fx28.fr7.POSTED!not-for-mail Message-ID: From: Mike H Reply-To: Mike Hopkins Newsgroups: comp.lang.ada Subject: Re: Reading data from file References: MIME-Version: 1.0 Content-Type: text/plain;charset=us-ascii;format=flowed User-Agent: Turnpike/6.07-M (<8M2$+z7w77P$i5diWa+NqJsa87>) NNTP-Posting-Host: 83.104.138.185 X-Complaints-To: abuse@demon.net X-Trace: 1393957125 83.104.138.185 (Tue, 04 Mar 2014 18:18:45 UTC) NNTP-Posting-Date: Tue, 04 Mar 2014 18:18:45 UTC Date: Tue, 4 Mar 2014 18:08:15 +0000 X-Received-Body-CRC: 3941166465 X-Received-Bytes: 3409 Xref: news.eternal-september.org comp.lang.ada:18778 Date: 2014-03-04T18:08:15+00:00 List-Id: In message , Laurent writes >Still trying to solve an exercise. I am supposed to develop a procedure >which reads the data from a txt file. In Ada (or at least in Ada95) a piece of text is a String. A String is an unconstrained (i.e. variable length) array of Characters. A Character takes any of the 128 ASCII possible values so non printable characters are also visible. Anything you can do with an array you can do with a string, and vice-versa. So, for each line of input I suggest that you read it as a String and the parse the string in order to separate key word from data. Thus, in the case of your line of text >Gender: male <== reading fails with atio_enumio error I suggest that having read the complete line you first verify that characters 1..8 are indeed "Gender. " and then parse the following non-space text. Furthermore if, as it would appear, your enumeration type contains less than a handful of values you forget enumeration_io. I hope the following code will indicate what I mean. with Text_IO; procedure Laurent is type Gender is (male, female, cross_gender); subtype Some_arbitrary_range is positive range 1..10; -- ID_line, Name_line : String (Some_arbitrary_range); Gender_line : String (Some_arbitrary_range); -- Numdepend_line, etc Line_length : Positive; begin Text_IO.Get_line (Item => Gender_Line, Last => Line_Length); case Line_length is when 1..8 => -- insert code to report that the line appears to be too short null; when others => if Gender_Line (1..8) /= "Gender. " then -- insert code to report that the line appears to be ill formed null; else case Gender_Line (9) is when 'M' | 'm' => -- insert code here to parse ID_line (10..Line_length) -- looking for "ale" null; when 'F' | 'f' => -- insert code here to parse ID_line (10..Line_length) -- looking for "emale" null; when 'C' | 'c' => -- etc null; when others => -- report an error null; end case; null; end if; end case; end Laurent; -- Mike Swim? Naturally at Severn Vale