comp.lang.ada
 help / color / mirror / Atom feed
* Reading text files with different data types
@ 2004-05-10  0:09 Isa
  2004-05-10  2:21 ` Jeff C,
  2004-05-10  5:41 ` Simon Wright
  0 siblings, 2 replies; 3+ messages in thread
From: Isa @ 2004-05-10  0:09 UTC (permalink / raw)


I'm trying to write a program to read points from a text file into an
array of records.
Each record corresponds to a line in the file, consisting of an
alphanumberic 6 character line, a space, a floating point number,
another space, then a final floating point number. (a name and 2
coordinates).

I'm completely at a loss as to how to read this in -- Ada.text_IO can
read it fine as a string - but I need to do calculation on the
floating point numbers(which could be with or without decimal points,
largest number to be stored  1000.00)

I don't think I can use streams - as it *must* be a text fine that is
read in, not a binary file.

Can anyone help me? I'm not asking for code - I just need a shove in
the right direction....

Thanks....any help will be VERY gladly appreciated



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

* Re: Reading text files with different data types
  2004-05-10  0:09 Reading text files with different data types Isa
@ 2004-05-10  2:21 ` Jeff C,
  2004-05-10  5:41 ` Simon Wright
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff C, @ 2004-05-10  2:21 UTC (permalink / raw)


Assuming you have been taught about generics, look at

Text_IO.Float_IO
which is generic and can be instantiated for any floating point type.

It can read floats from a file or from a string.

You can mix calls to this with standard text_IO stuff for the text data.


"Isa" <yorkbiatch@hotmail.com> wrote in message
news:6e837805.0405091609.bb1a850@posting.google.com...
> I'm trying to write a program to read points from a text file into an
> array of records.
> Each record corresponds to a line in the file, consisting of an
> alphanumberic 6 character line, a space, a floating point number,
> another space, then a final floating point number. (a name and 2
> coordinates).
>
> I'm completely at a loss as to how to read this in -- Ada.text_IO can
> read it fine as a string - but I need to do calculation on the
> floating point numbers(which could be with or without decimal points,
> largest number to be stored  1000.00)
>
> I don't think I can use streams - as it *must* be a text fine that is
> read in, not a binary file.
>
> Can anyone help me? I'm not asking for code - I just need a shove in
> the right direction....
>
> Thanks....any help will be VERY gladly appreciated





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

* Re: Reading text files with different data types
  2004-05-10  0:09 Reading text files with different data types Isa
  2004-05-10  2:21 ` Jeff C,
@ 2004-05-10  5:41 ` Simon Wright
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Wright @ 2004-05-10  5:41 UTC (permalink / raw)


yorkbiatch@hotmail.com (Isa) writes:

> I'm trying to write a program to read points from a text file into
> an array of records.

> Each record corresponds to a line in the file, consisting of an
> alphanumberic 6 character line, a space, a floating point number,
> another space, then a final floating point number. (a name and 2
> coordinates).

> I'm completely at a loss as to how to read this in -- Ada.text_IO
> can read it fine as a string - but I need to do calculation on the
> floating point numbers(which could be with or without decimal
> points, largest number to be stored 1000.00)

Try splitting the input line at the spaces and then the
type-name'Value attribute:

  X : Float;

  X := Float'Value ("123.456");

-- 
Simon Wright                               100% Ada, no bugs.



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

end of thread, other threads:[~2004-05-10  5:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-10  0:09 Reading text files with different data types Isa
2004-05-10  2:21 ` Jeff C,
2004-05-10  5:41 ` Simon Wright

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