Thread View: alt.flame.pascal
4 messages
4 total messages
Started by Hugo Palma
Mon, 10 Mar 1997 00:00
Help !!! Can't save pointer list to file
Author: Hugo Palma
Date: Mon, 10 Mar 1997 00:00
Date: Mon, 10 Mar 1997 00:00
21 lines
1548 bytes
1548 bytes
I'm doing a project,but i'm just not able to save a variable of type LIST
as shown below.
I'm only able to save the first segment of the list,and none of the next.
Can anyone please help me.
Thanks.
type
list=^no;
no=record
v:integer;
seg:list;
end;
var
p:list;
Please reply to :
hmpalma@mail.telepac.pt
Re: Help !!! Can't save pointer list to file
Author: R.E.Donais
Date: Tue, 11 Mar 1997 00:00
Date: Tue, 11 Mar 1997 00:00
32 lines
2244 bytes
2244 bytes
"Hugo Palma" <hmpalma@mail.telepac.pt> wrote:
>I'm doing a project,but i'm just not able to save a variable of type LIST
>as shown below.
>I'm only able to save the first segment of the list,and none of the next.
>Can anyone please help me.
>Thanks.
>
>type
> list=^no;
> no=record
> v:integer;
> seg:list;
> end;
>
>var
> p:list;
>
Mmmmm, you stopped short of including the code that you have that succeeds in
writing the first entry. A small example would have been nice.
Have your procedure that writes the list implement a while loop, stopping when
the list pointer becomes nil. After writing the current list entry it would
advance the pointer to the "next" seg. This assumes that the last entry in the
list is identified by a nil seg field. Also be certain that the pointer you use
to "walk" the list is a local variable or a parameter by value. You wouldn't
want to loose the list by changing the actual list pointer.
...red
cc
Re: Help !!! Can't save pointer list to file
Author: Hiroyuki Shimada
Date: Tue, 11 Mar 1997 00:00
Date: Tue, 11 Mar 1997 00:00
46 lines
2655 bytes
2655 bytes
Hello.
Hugo Palma <hmpalma@mail.telepac.pt> wrote in article <01bc2d75$4541e060$LocalHost@host.telepac.pt>...
> I'm doing a project,but i'm just not able to save a variable of type LIST
> as shown below.
> I'm only able to save the first segment of the list,and none of the next.
> Can anyone please help me.
> Thanks.
>
> type
> list=^no;
> no=record
> v:integer;
> seg:list;
> end;
>
> var
> p:list;
Make a new record type to save and load the data:
type
no_for_save_and_load = record { Define a record type which doesn't have }
v: integer; { the pointer field to next record. }
end;
var
f: file of no_for_save_and_load;
data: no_for_save_and_load;
begin
assign(f, 'filename.dat'); { if Delphi, assignfile() }
reset(f);
while p^.seg <> nil do begin
data.v := p^.v; { substitute all fields to the record type data }
writeln(f, data); { save }
p := p^.seg; { substitute next record }
end;
close(f); { if Delphi, closefile() }
end;
-----------------------------------------------------------------------
Mail: shimaden@annie.co.jp Home Page: http://www.annie.co.jp/~shimaden/
Hiroyuki Shimada
-----------------------------------------------------------------------
Re: Help !!! Can't save pointer list to file
Author: Haruo Toda
Date: Wed, 12 Mar 1997 00:00
Date: Wed, 12 Mar 1997 00:00
72 lines
2763 bytes
2763 bytes
In article <01bc2d75$4541e060$LocalHost@host.telepac.pt>,
"Hugo Palma" <hmpalma@mail.telepac.pt> wrote:
> I'm doing a project,but i'm just not able to save a variable of type LIST
> as shown below.
> I'm only able to save the first segment of the list,and none of the next.
> Can anyone please help me.
> Thanks.
>
> type
> list=^no;
> no=record
> v:integer;
> seg:list;
> end;
>
> var
> p:list;
>
>
>
> Please reply to :
> hmpalma@mail.telepac.pt
Hi, Hugo,
Your code fragment is not enough. The 'list' type is typical record for
'Linear List' items. There are some way to build a linear list from this
type. How do you build it?
for very easy example, consider the following code;
Program SomeProgram;
type
list = ^no
no = record
v : integer;
seg : list
end;
var
root, p : list;
f : file of integer;
begin
(* building up a LIFO linear list *)
root := nil;
while {more data} do begin
new(p);
p^.v := {data};
p^.seg := root;
root := p
end;
(* save it *)
{set up f}
p := root;
while p<>nil do begin
write(f, p^.v);
p := p^.seg
end;
{close f}
...
end.
It is important that saving pointer itself (i.e. saving p or p^.seg )
has no meaning and must be avoided. Because pointer variables are
carrying addresses of contents and the addresses varies run-to-run
(under many modern OSs).
Haruo.
--
Haruo Toda, Niigata Univ.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads