Ady96
Ady96

Reputation: 716

Incompatible type for argument for struct array

I have a structure defined as

struct Bod{
  int x, y;
};

Then I have a function

void add(struct Bod* s) {
    h[++nh] = s;
}

And in next function, I tried to pass array into the previous function, which gives me error Incompatible type for argument 1 of function add()

void bfs(struct Bod* body, int start_index){

    struct Bod* v;
    add(body[start_index]);
    ...
}

And in main, I have created this array of struct like this

struct Bod body[m*n];

What did I miss?

Upvotes: 1

Views: 784

Answers (1)

frslm
frslm

Reputation: 2978

Since body[start_index] gives you one element of body at index start_index, you end up passing in that single element to add().

If you want to pass in the array itself, you just need to pass in body as-is:

add(body);

Or, to pass in the array starting at a given index:

add(&body[start_index]);

Upvotes: 2

Related Questions