user3583443
user3583443

Reputation: 1

function calling of a structure error

I'm currently having problems trying to figure out the error of a certain part of the code that involves using a function that uses a structure of struct a and struct b

RectT a, b, recs[50];
int acount, bcount;
....

....
/* checks to see if the chk_overlap function returns a 1, if it does it adds 1 to bcount and acount */
if(chk_overlap(recs, a) == 1)
{
  bcount++;
}
if(chk_overlap(recs, b) == 1)
{
  acount++;
}

The function being called is

int chk_overlap(RectT *r1, RectT *r2){}

and the structure is

typedef struct rect
{
  int x;
  int y;
  int w;
  int h;
}RectT;

took off the code inside as this is a homework assignment

The current error is giving that im getting is

gcc -Wall -g -ansi -o xtst rec02.c
rec02.c: In function 'main':
rec02.c:64: error: incompatible type for argument 2 of 'chk_overlap'
rec02.c:69: error: incompatible type for argument 2 of 'chk_overlap'

Upvotes: 0

Views: 54

Answers (2)

user3581454
user3581454

Reputation: 101

You declared function to take pointers to that structure, but in code, you are trying to pass not pointer, but structrure itself, as a value. You should call:

chk_overlap(recs, &b)

Upvotes: 1

timrau
timrau

Reputation: 23058

chk_overlap() accepts two RectT *. Thus, you could call it as

if(chk_overlap(recs, &a) == 1)

Note the & operator which takes the address of a.

Upvotes: 2

Related Questions