comp.lang.ada
 help / color / mirror / Atom feed
From: Mike H <postmaster@ada-augusta.demon.co.uk>
Subject: Re: Reading data from file
Date: Tue, 4 Mar 2014 18:08:15 +0000
Date: 2014-03-04T18:08:15+00:00	[thread overview]
Message-ID: <orIsCUDPahFTFwJN@ada-augusta.demon.co.uk> (raw)
In-Reply-To: a8343425-3e25-4592-a5f5-5395f4a70221@googlegroups.com

In message <a8343425-3e25-4592-a5f5-5395f4a70221@googlegroups.com>, 
Laurent <daemon2@internet.lu> 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
<http://www.severnvalesc.org/>

  parent reply	other threads:[~2014-03-04 18:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-04  9:46 Reading data from file Laurent
2014-03-04 16:17 ` adambeneschan
2014-03-04 18:08 ` Mike H [this message]
2014-03-04 21:27   ` Laurent
2014-03-04 21:35     ` Laurent
2014-03-04 21:42     ` Niklas Holsti
2014-03-05 13:59     ` Mike H
2014-03-05 20:33       ` Laurent
2014-03-05 21:00         ` Jeffrey Carter
2014-03-05 21:13           ` Laurent
2014-03-05 21:25             ` Niklas Holsti
2014-03-05 21:56               ` Laurent
2014-03-06  8:35                 ` Dmitry A. Kazakov
2014-03-07 21:55                   ` Laurent
2014-03-08  6:56                     ` Dmitry A. Kazakov
2014-03-08 21:21                       ` Laurent
2014-03-09 22:39                         ` Laurent
2014-03-10  2:42                           ` Jeffrey Carter
2014-03-11 20:54                             ` Laurent
2014-03-08  9:00                     ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox