PDA

View Full Version : Free Pascal Compiler - File Handling




satans_banjo
Jan 10, 2006, 07:26 AM
Ok this is quite urgent - I've got some pascal work to do for tomorrow and the exercise is about file handling - problem is the teacher only told us about file handling on windows

i've tried writing the same thing i would for windows but replacing the file path with just "/" as the root but that didnt work. the compiler had no problems but the terminal did this when i ran it:

Loading...
Runtime error 2 at $00002354
$00002354
$0000274C
$00020954
$00001CAC
$00001B4C
$00000001


the weird thing is, i didn't put a string that says 'loading...' in the code. it must have been added by the compiler

any advice would be much appreciated



robbieduncan
Jan 10, 2006, 07:46 AM
If you post the relevant part of the code we might have a chance!

satans_banjo
Jan 10, 2006, 07:50 AM
thanks for the quick reply

here's the main part:

begin
assign(f1,'/file.car');
load;
menu;
end.

heres the load procedure:


procedure load;
begin
writeln('Loading Data Now...');
reset(f1);
i:=0;
while not eof(f1) do
begin
i:=i+1;
seek(f1,i);
read(f1,car[i]);
end;
close(f1);
count:=i;
end;


and here's the save procedure


procedure save;
begin
writeln('Saving data now...');
rewrite(f1);
for i:=1 ro count do
begin
seek(f1,i);
write(f1,car[i]);
end;
close(f1);
end;


thanks for reading

danny_w
Jan 10, 2006, 08:13 AM
Do you have file r/w permissions for the root path, and does the file currently exist when you run the program?

robbieduncan
Jan 10, 2006, 08:20 AM
Where is car (the array) defined? Where is save called? You call menu but not save!

satans_banjo
Jan 10, 2006, 08:48 AM
sorry. schoolboy error

this is the array, in the enterdata procedure:


procedure enterdata;
begin
car[1].regnum := 'D390 HDJ';
car[1].ownname:= 'Ben Wadsworth';
car[1].make := 'Bentley';
car[1].model := 'Continental GT';
car[2].regnum := 'F387 DJK';
car[2].ownname:= 'Alex Branchini';
car[2].make := 'Fiat';
car[2].model := 'Punto';
car[3].regnum := 'G768 SKF';
car[3].ownname:= 'Tom Scott-Soundy';
car[3].make := 'Hummer';
car[3].model := 'H2';
car[4].regnum := 'B847 DJH';
car[4].ownname:= 'Rory Dishman';
car[4].make := 'Mercedes-Benz';
car[4].model := 'S-Class';
car[5].regnum := 'H487 FNS';
car[5].ownname:= 'Josh Holloway';
car[5].make := 'Jaguar';
car[5].model := 'X-Type';
end;


and here is the new main section:

begin
assign(f1,'/file.car');
enterdata;
save;
load;
menu;
end.


thanks for pointing that out

EDIT: just compiled it and it works!

thanks macrumors! and special thanks to robbieduncan and danny_w!