need help with reading file. its doesnt do it for some reason.

[b][red]This message was edited by feed_me59 at 2003-3-1 4:16:37[/red][/b][hr]
I am having trouble reading from a textfile. Here is a copy of the procedure for reading it in:
{====================================================}
EXTRA INFO:
ship_type_array = ARRAY OF ship_type;
{-------------------------------------}
ship_type = RECORD
name :STRING [15];
capacity :cargo_type;
amount :cargo_type;
schedule :sched_ptr;
END;
{-------------------------------------}
PROCEDURE read_ships (VAR rs_ship_info :ship_type_array);
VAR
I :INTEGER;
BEGIN
ASSIGN (specsfile, specspath);
RESET (specsfile);
FOR I := 1 TO Max_Ships DO
BEGIN
READLN (specsfile, rs_ship_info[I].name);
READLN (specsfile, rs_ship_info[I].capacity.mass);
READLN (specsfile, rs_ship_info[I].capacity.volume);
WRITELN (rs_ship_info [I].name);
WRITELN (rs_ship_info [I].capacity.mass);
WRITELN (rs_chip_info [I].capacity.volume);
READLN;
END;
CLOSE (specsfile);
END;

there is no run-time error, or any one at all reported by the compiler/debugger.
however, after i READLN into the array, the fields in records do not WRITELN! i just get blanks for the name, and 0s for the numerical data. the text file is NOT EMPTY! and it is in the same directory.
please help me, or write an email if you require more specific information or the source code. thank you!

ok, ive decided to put in the source code right away: (its not finished yet, of course, but i will be working on it, except for the readfile procedure)... :(
================
PROGRAM Harbor_Sim (INPUT, OUTPUT, specsfile, schedfile);
CONST
specspath = 'shipspec.txt'; {Path of file for ship specs}
schedpath = 'shipsch.txt'; {Path of file for ship schedules}
RANDSEED = 150;
Max_Ships = 100; {Maximum number of ships}
harbor1 = 'Yokohama';
harbor2 = 'Singapore';
harbor3 = 'Sao Paulo';
harbor4 = 'Hamburg';
harbor5 = 'New York';
TYPE
sched_ptr = ^sched_type_array;
harbor_type = RECORD
city_name :STRING [10];
END;
sched_type = RECORD
location :harbor_type;
destination :harbor_type;
time_to_travel :INTEGER;
date :INTEGER; {What day the ship is going to leave its
location in order to reach its destination}
END;
cargo_type = RECORD
mass :INTEGER;
volume :INTEGER;
END;
ship_type = RECORD
name :STRING [15];
capacity :cargo_type;
amount :cargo_type;
schedule :sched_ptr;
END;
ship_type_array = ARRAY [1..Max_Ships] OF ship_type;
sched_type_array = ARRAY [1..Max_Ships] OF sched_type;
VAR
run_again :CHAR;
specsfile, schedfile :TEXT;
{============================================================================}
PROCEDURE clear_screen;
VAR
I :INTEGER;
BEGIN
FOR I:= 1 TO 50 DO
BEGIN
WRITELN;
END;
END;
{----------------------------------------------------------------------------}
PROCEDURE read_ships (VAR rs_ship_info :ship_type_array);
VAR
I :INTEGER;
BEGIN
ASSIGN (specsfile, specspath);
RESET (specsfile);
FOR I := 1 TO Max_Ships DO
BEGIN
READLN (specsfile, rs_ship_info[I].name);
READLN (specsfile, rs_ship_info[I].capacity.mass);
READLN (specsfile, rs_ship_info[I].capacity.volume);
WRITELN (rs_ship_info [I].name);
WRITELN (rs_ship_info [I].capacity.mass);
READLN;
END;
CLOSE (specsfile);
END;
{----------------------------------------------------------------------------}
PROCEDURE read_schedules (VAR rsch_ship_info :sched_type_array);
VAR
I :INTEGER;
BEGIN
ASSIGN (schedfile, schedpath);
RESET (schedfile);
WRITE ('Reading schedules... ');
FOR I := 1 TO Max_Ships DO
BEGIN
READLN (schedfile, rsch_ship_info [I].location.city_name);
END;
WRITELN (' done.');
CLOSE (schedfile);
END;
{----------------------------------------------------------------------------}
PROCEDURE write_schedules (wsch_ship_info :sched_type_array);
VAR
I :INTEGER;
BEGIN
ASSIGN (schedfile, schedpath);
REWRITE (schedfile);
clear_screen;
WRITE ('Writing new schedule... ');
FOR I := 1 TO Max_Ships DO
BEGIN
WRITELN (schedfile, wsch_ship_info [I].destination.city_name);
END;
WRITE (' done.');
CLOSE (schedfile);
READLN;
END;
{----------------------------------------------------------------------------}
PROCEDURE randomization (VAR ship_infor :ship_type_array);
VAR
I :INTEGER;
BEGIN
RANDOMIZE;
FOR I:= 1 TO Max_Ships DO
BEGIN
ship_infor[I].amount.mass :=
ABS(RANDOM (ship_infor[I].capacity.mass));
ship_infor[I].amount.volume :=
ABS(RANDOM (ship_infor[I].capacity.volume));
END;
END;
{----------------------------------------------------------------------------}
PROCEDURE menu;
BEGIN
WRITELN (' 1. ', harbor1);
WRITELN (' 2. ', harbor2);
WRITELN (' 3. ', harbor3);
WRITELN (' 4. ', harbor4);
WRITELN (' 5. ', harbor5);
END;
{----------------------------------------------------------------------------}
PROCEDURE ask_to_transport (VAR the_location,
the_destination :harbor_type);
VAR
choose_city, choose_city2 :INTEGER;
BEGIN
menu;
WRITE ('Which city do you want to transport from: ');
READLN (choose_city);
WHILE (choose_city <> 1) AND (choose_city <> 2) AND
(choose_city <> 3) AND (choose_city <> 4) AND (choose_city <> 5) DO
BEGIN
menu;
WRITE ('Please choose a number between 1 and 5: ');
READLN (choose_city);
end;
IF choose_city = 1 THEN
the_destination.city_name := harbor1
ELSE IF choose_city = 2 THEN
the_destination.city_name := harbor2
ELSE IF choose_city = 3 THEN
the_destination.city_name := harbor3
ELSE IF choose_city = 4 THEN
the_destination.city_name := harbor4
ELSE IF choose_city = 5 THEN
the_destination.city_name := harbor5;
clear_screen;
menu;
WRITE ('Which city do you want to transport to: ');
READLN (choose_city2);
WHILE (choose_city2 <> 1) AND (choose_city2 <> 2) AND
(choose_city2 <> 3) AND (choose_city2 <> 4) AND (choose_city2 <> 5)
OR (choose_city2 = choose_city) DO
BEGIN
menu;
IF (choose_city2 = choose_city) THEN
BEGIN
WRITE ('Please do not choose the same destination as the ');
WRITELN ('location');
END;
WRITE ('Please choose a number between 1 and 5: ');
READLN (choose_city2);
end;
choose_city := choose_city2;
IF choose_city = 1 THEN
the_location.city_name := harbor1
ELSE IF choose_city = 2 THEN
the_location.city_name := harbor2
ELSE IF choose_city = 3 THEN
the_location.city_name := harbor3
ELSE IF choose_city = 4 THEN
the_location.city_name := harbor4
ELSE IF choose_city = 5 THEN
the_location.city_name := harbor5;
clear_screen
END;
{----------------------------------------------------------------------------}
PROCEDURE what_to_transport (the_cargo :cargo_type);
BEGIN
WRITELN ('What is the mass of the cargo you want to transport?');
WRITE ('Please round it up to the nearest integer: ');
READLN (the_cargo.mass);
WRITELN ('How many cargo boxes will you need?');
WRITE ('Please answer in multiples of 20 feet of length: ');
READLN (the_cargo.volume);
END;
{----------------------------------------------------------------------------}
PROCEDURE findship (fs_location, fs_destination :harbor_type;
VAR fs_schedules :sched_type_array);
VAR
I :INTEGER;
J :INTEGER;
BEGIN
J := 0;
FOR I := 1 TO Max_Ships DO
BEGIN
IF (fs_schedules [I].location.city_name = fs_location.city_name) AND
(fs_schedules [I].destination.city_name = fs_destination.city_name)
THEN
BEGIN
J := J + 1;
END;
END;
WRITELN (J, ' ships found!');
END;
{----------------------------------------------------------------------------}
PROCEDURE feasible (f_ship_info :ship_type_array;
f_cargo :cargo_type);
VAR
I :INTEGER;
BEGIN
FOR I := 1 TO Max_Ships DO
BEGIN
WRITELN (f_ship_info [I].name);
{READLN;}
END;
END;
{----------------------------------------------------------------------------}
PROCEDURE main_calculations (mc_ship_info :ship_type_array;
VAR mc_location, mc_destination :harbor_type;
mc_ship_schedules :sched_type_array;
mc_cargo :cargo_type);
BEGIN
findship (mc_location, mc_destination, mc_ship_schedules);
feasible (mc_ship_info, mc_cargo);
END;
{============================================================================}
PROCEDURE main_loop;
VAR
ml_ship_specs :ship_type_array;
ml_ship_schedules :sched_type_array;
ml_location, ml_destination :harbor_type;
ml_cargo :cargo_type;
BEGIN
clear_screen;
read_ships (ml_ship_specs);
read_schedules (ml_ship_schedules);
randomization (ml_ship_specs);
ask_to_transport (ml_location, ml_destination);
main_calculations (ml_ship_specs, ml_location, ml_destination,
ml_ship_schedules, ml_cargo);
write_schedules (ml_ship_schedules);
END;
{============================================================================}
BEGIN {MAIN}
run_again := 'Y';
REPEAT
main_loop;
WRITELN ('Do you want to run the program again? ');
READLN (run_again);
WHILE (run_again <> 'Y') AND (run_again <> 'y') AND
(run_again <> 'N') AND (run_again <> 'n') DO
BEGIN
WRITELN ('Please enter ''Y'' or ''N'': ');
READLN (run_again);
END;
UNTIL (run_again = 'N') OR (run_again = 'n');
clear_screen;
WRITELN ('BYE! Thank you for using this program.');
READLN;
END.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories