comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: File Problem. Please help..
Date: 1996/08/01
Date: 1996-08-01T00:00:00+00:00	[thread overview]
Message-ID: <4tqdtv$2kb@newsbf02.news.aol.com> (raw)
In-Reply-To: 4tp9re$r7a@news.us.net


mhall59@mail.us.net (Michael W. Hall) writes:
> I have figured out that I got an error because
> my values were higher than 32767(or whatever
> is the largest int value) How can I use a 16 bit
> or 32 bit number? Is there a way to set this?
     First, it looks like you're using an Ada 83 compiler, so I'll answer
in terms of Ada 83.  The "cheap and dirty" way to fix the problem of
integer values higher than 32767 is to see if your compiler provides a
type Long_Integer, and use that instead of Integer.
     However, I don't recommend that, because Ada provides a much more
portable solution!  Looking at your data file, I see that your integers
range up to 104570.  Let's be conservative and say that your integers can
range up to a half million.  In Ada you can define a user-defined type:

type My_Int is range 0 .. 500_000;

Now, use My_Int instead of Integer (or Long_Integer).  You'll have to
instantiate Integer_IO for the type My_Int.
     With the declaration above, each Ada compiler will automatically
select the appropriate integer type.  A compiler that implements type
Integer with 32 bits will select Integer, while a compiler that implements
type Integer with 16 bits will select Long_Integer if it's available.  All
automatically, so your code is perfectly portable!
> Also how can I read the strings into a single
> variable while looping if they are different lengths?
     I like to use Get_Line for strings instead of Get.  You need to
declare not only the String variable (Name), but its length as an Integer
(e.g., Name_Len : Integer;).  Then do
Text_IO.Get_Line(File => Data_File, Item => Name, Last => Name_Len);
Name_Len will contain the number of characters in the line you read in,
and the first Name_Len characters of Name will be stored into (the rest of
Name will be unchanged).  If you don't want your Get_Data to store into a
global variable, add an extra out parameter for the length, and store into
that parameter and Plant_Name.
     I hope this helps.  For more about user-defined types and
portability, download the Ada Tutor program at the Web or FTP site below
my signature.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




  reply	other threads:[~1996-08-01  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-31  0:00 File Problem. Please help Michael W. Hall
1996-08-01  0:00 ` Michael W. Hall
1996-08-01  0:00   ` John Herro [this message]
1996-08-03  0:00     ` Michael W. Hall
replies disabled

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