Whenever I go to read in record from a file in Ada, I always get an error. The goal of the program is to read (from a file) an integer which is how many items needed to be recorded, in a last name consisting of (at most) 12 letters, a first name consisting of (at most) 12 letters, and a float value, then store those into a record.
This was from AdaGIDE:
record2.adb:32:04: invalid parameter list in call (use -gnatf for details)
My code:
with Ada.Text_IO, Ada.float_Text_IO, ada.Integer_Text_IO;
use Ada.Text_IO, Ada.float_Text_IO, ada.Integer_Text_IO;
procedure Record2 is
TYPE Testrec IS
record
test1 : string (1..12);
test2 : string (1..12);
test3 : float;
END RECORD;
T: Testrec;
Lt: Integer;
numitem: integer;
random1: Ada.Text_IO.File_Type;
begin -- Record2
Ada.Text_IO.Open(File => random1, Mode => Ada.Text_IO.In_File, Name => "info1.dat");
Get_Line(File => random1, Item => Testrec, Last => Lt);
Put(T.test1);
Put(T.Test2);
Put(T.Test3);
end Record2;
info1.dat’s contents (no extra spaces or lines, just from “L” to “0”:
LastName FirstName 4.00
My problems is the Get_Line, that I know. LastName is padded with spaces, filling the 12 characters, the same goes for FirstName. Then the float is taken for its value in general. What exactly am I doing wrong?
Basically, you’re using Get_Line, which reads strings, to attempt to read an instance of a record.
Since this looks like a homework assignment (which is okay), I’ll give you a hint:
Try reading the fields individually.
That’s not enough to totally solve your problem, but it’ll get you further, from which point you can try to work out the rest.