Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-01

Can someone help me to debug and correct this code?

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Goksie

dear all,

const maxliststore=30;
strmaxlen=20;
type objecttype=string[strmaxlen];
list=record
object:array[1..maxliststore]of objecttype;
last:integer;
End;
var choice:char;
position,number:integer;
str:Objecttype;
1st:List;
procedure copyobject(var obj1,obj2:Objecttype);
begin obj1:=obj2;
end;
procedure displayobj(obj:Objjecttype);
begin
write('',obj,'');
end;
procedure initialise(var 1st:list);
begin 1st.Last:=0
end;
function insert(ob:Objjecttype;position:integer;var 1st:List):integer;
vari:integer;
begin
insert:=0;
if not((position<1)or(position>1st.Last+1)
                    or(position>maxliststore))then
begin
for i:=1st.last downto position do
               copyobject(1st.object[i+1],1st.object[i]);
copyobject(1st.object[position],obj);
1st.last:=1st.last+1;
insert:=1;
end
end;
function delete(position:integer;var 1st:List):integer;
var i:integer;
begin
if not((position<1)or(position>1st.last))then
for i:=position to 1st.last do
copyobject(1st.object[i],1st.object[i+1]);
1st.last:=1st.last-1;
delete:=1;
end
end;
procedure displaylist(var1st:List);
var i:integer;
begin
for i:=1 to 1t.last do
displayobj(1st.object[i];
end;

Goksie

Reply by email

Daniël Mantione
to Goksie

Op Sun, 14 Jan 2007, schreef Goksie:

dear all,

Sorry, but this code is an unreadable mess and I have no idea what this stuff isw supposed to do. I see some things that are illegal such as starting an identifier with a number, which you might want to fix first. Can you please format and indent your code in a more readable form, so we can at least read it?

Daniël

Show quoted text 59 lines
const maxliststore=30; strmaxlen=20; type objecttype=string[strmaxlen]; list=record object:array[1..maxliststore]of objecttype; last:integer; End; var choice:char; position,number:integer; str:Objecttype; 1st:List; procedure copyobject(var obj1,obj2:Objecttype); begin obj1:=obj2; end; procedure displayobj(obj:Objjecttype); begin write('',obj,''); end; procedure initialise(var 1st:list); begin 1st.Last:=0 end; function insert(ob:Objjecttype;position:integer;var 1st:List):integer; vari:integer; begin insert:=0; if not((position<1)or(position>1st.Last+1) or(position>maxliststore))then begin for i:=1st.last downto position do copyobject(1st.object[i+1],1st.object[i]); copyobject(1st.object[position],obj); 1st.last:=1st.last+1; insert:=1; end end; function delete(position:integer;var 1st:List):integer; var i:integer; begin if not((position<1)or(position>1st.last))then for i:=position to 1st.last do copyobject(1st.object[i],1st.object[i+1]); 1st.last:=1st.last-1; delete:=1; end end; procedure displaylist(var1st:List); var i:integer; begin for i:=1 to 1t.last do displayobj(1st.object[i]; end; Goksie _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Darius Blaszijk
to Daniël Mantione

Goksie,

You could also start reading the output of the FPC compiler :) Normally it gives hints, warning and errors where to start looking for to correct your code. Iow don't ask for the obvious before looking yourself first.

Darius

Earlier message 90 lines
----- Original Message ----- From: "Daniël Mantione" To: ; "FPC-Pascal users discussions" Sent: Sunday, January 14, 2007 11:26 PM Subject: Re: [fpc-pascal] Can someone help me to debug and correct this code? Op Sun, 14 Jan 2007, schreef Goksie: > dear all, Sorry, but this code is an unreadable mess and I have no idea what this stuff isw supposed to do. I see some things that are illegal such as starting an identifier with a number, which you might want to fix first. Can you please format and indent your code in a more readable form, so we can at least read it? Daniël > const maxliststore=30; > strmaxlen=20; > type objecttype=string[strmaxlen]; > list=record > object:array[1..maxliststore]of objecttype; > last:integer; > End; > var choice:char; > position,number:integer; > str:Objecttype; > 1st:List; > procedure copyobject(var obj1,obj2:Objecttype); > begin obj1:=obj2; > end; > procedure displayobj(obj:Objjecttype); > begin > write('',obj,''); > end; > procedure initialise(var 1st:list); > begin 1st.Last:=0 > end; > > function insert(ob:Objjecttype;position:integer;var 1st:List):integer; > vari:integer; > begin > insert:=0; > if not((position<1)or(position>1st.Last+1) > or(position>maxliststore))then > begin > for i:=1st.last downto position do > copyobject(1st.object[i+1],1st.object[i]); > copyobject(1st.object[position],obj); > 1st.last:=1st.last+1; > insert:=1; > end > end; > > function delete(position:integer;var 1st:List):integer; > var i:integer; > begin > if not((position<1)or(position>1st.last))then > for i:=position to 1st.last do > copyobject(1st.object[i],1st.object[i+1]); > 1st.last:=1st.last-1; > delete:=1; > end > end; > procedure displaylist(var1st:List); > var i:integer; > begin > for i:=1 to 1t.last do > displayobj(1st.object[i]; > end; > > Goksie > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > -------------------------------------------------------------------------------- > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email