Pointer to structures

Hello.

I have a structure like this:

[code]struct node{
int top;
struct node * topnext;
};[/code]

Then I have the following arrays.
[code]
struct node tops[n+1];
struct node * currtop[n+1];[/code]

where "tops" is an array of nodes, and currtop is an array of pointers to nodes.

Since both these arrays are not global, I have to pass pointers to these to functions in order to perform tasks on these arrays.

I tried passing just their addressed and using them like this:

[code]void foo(t1,&currtop,&tops)

void foo(int t1,struct node*ptr_curr,struct node*ptr_tops){

ptr_curr[t1]=ptr_tops[t1].topnext;

}
[/code]

but I get a compiler error which says :
incompatible types in assignment

What am I doing wrong?

Comments

  • An array variable is a pointer that hold the address of the first element. for example:

    #include

    void main() {
    char string[256];
    sscanf("world peace","%s",string);
    putchar(*string); //output will be: w
    putchar(*(string+2)); //output will be: r
    }
    Note that when calling sscanf the argument string was passed without the referencing symbol &. sscanf stores the sentence "world peace" into the address of the array string.

    Here is the error:
    foo(t1,&currtop,&tops)

    corrected:
    foo(t1,currtop,tops)



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion