I'm trying to pass an array of struct to a function that works with it and modify its content. I've read many articles but I still cannot find what I need.
I need to pass this array of struct to a function and work with the values of this array, and the modifications need to be global modifications.
Here, I'm actually sorting the values of the areas of this structure; the program gives me this warning and crashes:
warning: passing argument 1 of 'insersort' from incompatible pointer type [-Wincompatible-pointer-types]|
struct rectangle{
char name[MAXC];
float x;
float y;
float area;
float perimeter;
};
void insersort(struct rectangle *rect[],int k)
{
int i,j;
float x;
for(i=1;i<k;i++)
{
x=rect[i]->area;
j=i-1;
while(j>=0 && x<rect[j]->area)
{
rect[j+1]->area=rect[j]->area;
j--;
}
rect[j]->area=x;
}
return;
}
.....
I call the function like so:
struct rectangle rect[MAX];
insersort(rect,k);
struct rectangle rect[]or asstruct rectangle *rectbut not both. Yourstruct rectangle *rect[]is an array of pointers.insersort, the parameter should bestruct rectangle rect[]and allrect[n]->should be changed torect[n].