Thanks for the help with dynamic allocation of arrays.
Can any body help me with these two questions:
1) Is it possible to use a notation like the this in C: item->next_item->data->name = 'test name' and if it is, how is it done?
2) To get data out of an array by the help of pointers
type arraytype = array[1..100, 1..100] of interger;
var a: arraytype; k : ect.. ..
max :=0;
for k := 51 to 100 begin if A[50,k]>max then max := A[50,k]; end;
or
for k := 51 to 100 begin if A[k,50]>max then max := A[k,50]; end;
I am thinke of something like this not very nice example:
finish_ptr := addrs(A[50,100]) a_ptr := addrs(A[50,51]) max_ptr := a_ptr;
incrementing value/function ?
while a_ptr <> finish_ptr do begin (a_ptr := a_ptr + incrementionvalue) / (incremention function (a_prt)); if a_ptr > max_ptr then max_ptr := a_ptr; end;
If it is possible how do I calculate the incrementation value(x) for both A[50, 51+x] and A[51+x,50] or make a function/procedure?
3) Is there a good place or textbook to find information about working with pointers in pascal and datastructures?
I will be gratefull for any help,
klaus
Hello!
Klaus Friis Ãstergaard wrote:
- Is it possible to use a notation like the this in C: item->next_item->data->name = 'test name' and if it is, how is it done?
item^.next_item^.data^.name := 'test name'
- To get data out of an array by the help of pointers
[...] while a_ptr <> finish_ptr do begin (a_ptr := a_ptr + incrementionvalue) / (incremention function (a_prt));
This line cannot work. Maybe you mean something like this:
inc (a_ptr, incrementation_value div incrementation_function (a_prt));
if a_ptr > max_ptr then max_ptr := a_ptr; end;
With GNU Pascal, you can `inc' and `dec' pointers, and you can use them im `for' loops.
For your two-dimensional array, I do not however recommend to use a single pointer to access it. If you are accessing it with a single "index" anyway, better declare it as a one-dimensional array and use incrementation values (and functions) explicitly.
- Is there a good place or textbook to find information about working with pointers in pascal and datastructures?
I recently got a recommendation for "Oh! Pascal" which should be available in every library or book store. It covers Standard Pascal.
About GNU Pascal, type `info -f gpc'. Also, this list is a good place to ask.
Hope this helps,
Peter