comp.lang.ada
 help / color / mirror / Atom feed
* Re: Extracting Fields in Files
@ 2000-01-14  0:00 Christoph Grein
  2000-01-14  0:00 ` jmoor
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Grein @ 2000-01-14  0:00 UTC (permalink / raw)
  To: comp.lang.ada

When you do

 get_line (file => tip0125,
           item => rec01,
           last => rec01_length);

I presume you have defined rec01 (knowing that the maximum record
length is 212) as

  rec01: String (1..212);

Now read very carefully the corresponding chapter in the RM and you'll find
that reading exactly 212 characters will leave the LF (the end of line on
Unix, i.e. end of record, as you call it) unread. So your next get_line simply
reads the LF and returns an empty line.

As a simple work-around declare

  rec01: String (1..213);

(one longer than the maximum expected length) and a get_line will always
swallow the LF.









^ permalink raw reply	[flat|nested] 9+ messages in thread
* Extracting Fields in Files
@ 2000-01-13  0:00 Christoph Grein
  2000-01-13  0:00 ` jmoor
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Grein @ 2000-01-13  0:00 UTC (permalink / raw)
  To: comp.lang.ada

There's nothing wrong with method 1.

However you could improve by introducing subtypes:

subtype Data_Range    is Positive range  1 ..  8;
subtype Command_Range is Positive range 73 .. 77;

Command_code := rec01 (Command_Range);
Date_entered := rec01 (Data_Range);









^ permalink raw reply	[flat|nested] 9+ messages in thread
* Extracting Fields in Files
@ 2000-01-12  0:00 jmoor
  0 siblings, 0 replies; 9+ messages in thread
From: jmoor @ 2000-01-12  0:00 UTC (permalink / raw)


I am reading a file containing variable length records, the maximum
size being 250 bytes and the minimum size 5 bytes.

I read each record by doing the following:

While not end_of_file(tip0125) loop
  Get_line (tip0125,rec01,rec01_length);
  .
  .

                METHOD 1
I break the individual fields up by doing the following:

Command_code := rec01(073..077);
Date_entered := rec01(001..008);
.
.
.

                METHOD 2
After writing the program, I bought an Ada book (Bad timing. I should
have bought the book before writing the program) that said that the
individual fields should be broken up by using the "text_io.get" on
each field.


Is it inherently wrong to use METHOD 1 to break up individual fields
instead of METHOD 2. I am experiencing problems with ignoring some
records, but I would doubt that METHOD 1 is the culprit.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2000-01-15  0:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-14  0:00 Extracting Fields in Files Christoph Grein
2000-01-14  0:00 ` jmoor
  -- strict thread matches above, loose matches on Subject: below --
2000-01-13  0:00 Christoph Grein
2000-01-13  0:00 ` jmoor
2000-01-13  0:00   ` David C. Hoos, Sr.
2000-01-14  0:00     ` jmoor
2000-01-14  0:00       ` Ted Dennison
2000-01-15  0:00       ` Gautier
2000-01-12  0:00 jmoor

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