Reputation: 716
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
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