comp.lang.ada
 help / color / mirror / Atom feed
From: Michal Nowak <vinnie@inetia.pl>
To: "comp.lang.ada usegroup->mailing list gateway"
	<comp.lang.ada@ada.eu.org>
Subject: Re: Newbie question
Date: Mon, 24 Dec 2001 21:06:02 +0100
Date: 2001-12-24T21:06:02+01:00	[thread overview]
Message-ID: <mailman.1009224122.1572.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <a07cd3$gs$1@news8.svr.pol.co.uk>

On 01-12-24 at 13:52 Jasbinder S Uppal wrote:

>Hi, I've been subscribed to this news group for a long time (ok, when I
>first started using Ada, about 2 months ago!), but this is the first time
>I've actually had problems with the language and well, I was wondering if
>you guys can help me.

Welcome newbie, from another newbie :-))

>I've got this assignment for university that I have to do, and I am having
>problems with the first bit (Not a good sign, is it....).
>I've got a data file, which contains a line of data for a vehicle, and on
>the line, it gives a place name, a registration number, and the time that
>the car goes onto a motorway. A typical line is as follows....
>
>Barnsley    A123       22    15    40
>....
>....
>Where Barnsley is the place, A123 is the Registration number, and 22  15
>40 is the time (22:15:40). I've managed to get the Place name (using
>characters) and the registration number (using Strings), and putting it
>into
>a record, but I am unsure as to what to use for the time. I could (I think)
>use characters, but I need to manipulate the times later on in the program
>(which could be done by having the time as an integer), but because there
>are blanks in between the numbers, I am unsure as to how I can do this.
>Help
>me please....
>
>I appreciate any help given.
>
>Thanks.

As I said, I'm newbie also, but maybe this will be helpful.

Generally speaking, you may do like this:

...
Read place name,
Read registration number,
skip spaces,
read hour,
skip spaces,
read minute,
skip spces,
read second.
...

However, reading character after character from disc file is
inefficient way. My proposal is to read whole line into a string.
I assume, that hours, minutes and seconds are two digits
numbers (so the hour 7AM is presented as 07).
If no, you will have a bit more work.

Extract place name from string
Extract registration number
Skip Spaces
   You should know on which position in the string you are
   after skipping spaces. Let's call it Current_Position and
   let Whole_Line be of type String and consist line from
   input file.
   Hour := Integer'Value (Whole_Line(Current_Position .. Current'Position + 2) );

   Hour is of type Integer. It does not has to be predefined
   Integer. You may do something like this:
   type Hour_Type is range 0 .. 23; --this is declaration of
                                    --integer type
   Hour : Hour_Type;
   However, if you declare Hour_Type as a distinct type, you will
   have to cast result of Integer'Value to Hour_Type before assigning
   it to Hour:

   Hour := Hour_Type (Integer'Value (
                        Whole_Line(Current_Position .. Current'Position + 2) )
                     );

Do the same for minutes and seconds.
Exception handling is your task to do.

I'm not sure if this is very elegant way of doing it, but as
I said, I'm still a newbie.

I hope this will help you in some way.
Happy Ada programming,
-Mike
-----------------------------------------
                             ____|
                             \%/ |~~\
  O                                  |
 o>>        Mike Nowak               |
 T                                   |
/ >       vinnie@inetia.pl           |
http://www.geocities.com/vinnie14pl _|__




  reply	other threads:[~2001-12-24 20:06 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-24 13:52 Newbie question Jasbinder S  Uppal
2001-12-24 20:06 ` Michal Nowak [this message]
2001-12-24 21:13   ` martin.m.dowie
2001-12-25 12:36     ` Michal Nowak
2001-12-27 14:25       ` Alfred Hilscher
2001-12-29 21:54         ` Michal Nowak
2001-12-31 17:51           ` Jasbinder S Uppal
2002-01-01 21:26             ` Michal Nowak
  -- strict thread matches above, loose matches on Subject: below --
2009-03-12 13:29 Olivier Scalbert
2009-03-12 13:48 ` Ludovic Brenta
2009-03-12 14:16   ` Olivier Scalbert
2009-03-12 14:31     ` Ludovic Brenta
2009-03-12 14:32     ` stefan-lucks
2009-03-12 14:36       ` Ludovic Brenta
2009-03-12 17:14         ` stefan-lucks
2009-03-12 18:29           ` Adam Beneschan
2009-03-12 15:03       ` Jacob Sparre Andersen
2009-03-12 15:07   ` Robert A Duff
2009-03-12 17:16 ` Georg Bauhaus
2009-03-13  1:59 ` tmoran
2009-03-15 13:46 ` Olivier Scalbert
2009-03-21 18:08 ` Olivier Scalbert
2009-03-21 18:22   ` (see below)
2009-03-21 18:29     ` Olivier Scalbert
2009-03-21 18:36       ` Georg Bauhaus
2009-03-21 18:39         ` Olivier Scalbert
2009-03-22 12:40           ` (see below)
2009-03-22 13:19             ` Olivier Scalbert
2009-03-21 18:39       ` Jeffrey R. Carter
2009-03-23  8:24       ` Jean-Pierre Rosen
2007-11-23 13:22 Sir Chewbury Gubbins
2007-11-23 14:01 ` Sir Chewbury Gubbins
2007-11-24 16:49 ` Stephen Leake
2007-11-24 17:08   ` Peter C. Chapin
2007-11-25 19:25     ` Stephen Leake
2007-11-29  0:46   ` Robert A Duff
2005-07-18 11:26 Francisco J. Montoya
2005-07-18 13:14 ` Martin Dowie
2005-07-18 13:51   ` Alex R. Mosteo
2005-07-18 20:27     ` Martin Dowie
2005-07-18 15:28 ` Jeffrey Carter
2005-07-18 17:40 ` Martin Krischik
2005-07-03 17:58 newbie question e.coli
2005-07-03 18:32 ` Dmitry A. Kazakov
2004-08-04  6:42 Newbie Question leke
2004-08-04  8:55 ` Frank
2004-08-04  9:51 ` Martin Dowie
2000-05-25  0:00 Newbie question olsonm76
2000-05-26  0:00 ` Robert Dewar
1999-03-18  0:00 newbie question Kenneth Lee
1999-03-18  0:00 ` Andreas Winckler
1999-03-19  0:00   ` Kenneth Lee
1999-03-19  0:00     ` Michael F Brenner
1999-03-19  0:00       ` ELMO
1999-03-21  0:00       ` Matthew Heaney
1999-03-18  0:00 ` Tom Moran
1999-03-18  0:00   ` Kenneth Lee
1999-03-18  0:00     ` Nick Roberts
1999-03-19  0:00 ` Michael F Brenner
1999-03-19  0:00   ` Nick Roberts
1999-03-20  0:00     ` Nick Roberts
1999-03-19  0:00 ` robert_dewar
replies disabled

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