Code:
typedef struct Rect
{
double x;
double y;
char color;
double w; ///width
double h; //height
} RectT;
int main(int argc, char *argv[]){
RectT a, b, *recs;
RectT rectangle[50];
recs = rectangle;
Fixed my seg. fault.
Code:
int i;
for(i = 0; i < 50; i++){
recs[i].x = rand()%20;
recs[i].y = rand()%20;
recs[i].w = rand()%20;
recs[i].h = rand()%20;
}
Now working like a charm.
Code:
int chk_overlap(RectT *r1, RectT *r2){
if( (r1->x + r1->w) < (r2->x) || (r2->x + r2->w) < (r1->x) ) // if the rectangle is too far to the right or left to not possibly match up, return 0
return 0;
if( (r1->y + r1->h) < (r2->y) || (r2->y + r2->h) < (r1->y) ) // if the rectangle is too far above or below to not possibly match up, return 0
return 0;
return 1;
}
Reads in perfect now.