Structure containing pointer problem 
Author Message
 Structure containing pointer problem

Hi, I've got this problem.  I'm not sure whether it's my compiler and my
programming, so if you could help that would be great!

My program layout is like this

typedef struct{
    double **a;
    double **b;

Quote:
} mystruct;

void myfunction(double x,double y,double *result1,double *result2)
{
    stuff

Quote:
}

void usemyfunction(double x,double y,mystruct *new_struct)
{
     allcate memory to (*new_struct).a and (*new_struct).b
     stuff
     myfunction(x,y,&((*new_struct).a[i][j]),&((*new_struct).b[i][j]));
     stuff

Quote:
}

My problem is the following;
(i) after allocating some space to the pointers in mystruct
(ii) how do I pass in the address of one of the elements of a field of that
struct to myfunction(), like that above in usemyfunction()

when I do this the values of result1 and result2 (ie... thier locations) are
0, even though (*new_struct).a != 0?

I've also tried
&(new_struct->psi[i][j])
but that also comes through as a 0.

how do I pass the address of an element of an array of double pointers from
within a structure pointer??

--

Hybrid Physicist/Mathematician/Computer Scientist
University of Waikato
New Zealand (PRO "New ZEE-Land")

(In)famous last words : "Demi-Lich?  That's only half a Lich isn't it??"



Sat, 30 Nov 1996 07:49:36 GMT  
 Structure containing pointer problem

: typedef struct{
:     double **a;
:     double **b;
: } mystruct;

: void myfunction(double x,double y,double *result1,double *result2)
: {
:     stuff
: }

: void usemyfunction(double x,double y,mystruct *new_struct)
: {
:      allcate memory to (*new_struct).a and (*new_struct).b
:      stuff
:      myfunction(x,y,&((*new_struct).a[i][j]),&((*new_struct).b[i][j]));
:      stuff
: }

: My problem is the following;
: (i) after allocating some space to the pointers in mystruct
: (ii) how do I pass in the address of one of the elements of a field of that
: struct to myfunction(), like that above in usemyfunction()

: when I do this the values of result1 and result2 (ie... thier locations) are
: 0, even though (*new_struct).a != 0?

: I've also tried
: &(new_struct->psi[i][j])
: but that also comes through as a 0.

------->
           Have you allocated memory for (*new_struct).a[0], a[1], a[2]...
           ?
           Array of double pointers should take two phases.
              Phase I: allocate memory for pointers. (As in your program)
              Phase II: allocate memory for each pointer.  
                 ex:
                 for ( i = 0; i < 30; i ++ )
                   (*new_struct).a[i] = calloc ( 20, sizeof (double));

: how do I pass the address of an element of an array of double pointers from
: within a structure pointer??

  ------> As in your program.

     G o o d   L u c k !

     :)

                            Wiza  
                               (Wen-kae Tsao)
                               Computer Science & Information Engineering Dept.
                               National Taiwan University



Sat, 30 Nov 1996 15:28:27 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Pointers to Structure that contains pointer to Function

2. dereferencing pointer to a structure containing a pointer to int

3. reading a structure containing pointers

4. structure containing pointer to char over the network

5. How Do I fwrite() and fread() A Structure that contains pointers to dynamic data

6. self contained pointers to structures

7. memory block containing pointers, aka pointer to pointer i believe

8. Marshaling a structure containing a aray of different structures

9. how to dynamically allocate a structure containing pointer type structures?

10. Marshal problem with pointers to structures

11. printing a string contained in a structure

12. Sorting a last names that are contained within a structure

 

 
Powered by phpBB® Forum Software