I have a structure defined in C as
typedef struct shape{
int height;
int width;
} rectangle;
// just to denote the rectangles where width > height
typedef rectangle wider;
wider all[3]={{5,10},{2,4},{7,9}};
and I have a function that prints the height and width
void funct(wider shape){
printf("height: %d, width %d", shape.height, shape.width);
}
Now I want to achieve this for each shape, by creating threads and so I tried this:
pthread_t threads[sizeof(all)];
int count=0;
for(count=0; count <sizeof(all);++count)
{
if(pthread_create(&threads[count], NULL, funct,(wider*)all[count])!=0)
{
printf("Error in creating thread: %d",count);
break;
}
}
int i=0;
for(i=0; i<count; ++i)
{
if(pthread_join(threads[i],NULL)!=0)
printf ("Eroor joining: %d"+i);
}
However, this shows an error
expected 'void * (*)(void *)' but argument is of type 'void (*)(struct rectangle)'
I tried changing my function to
void funct(void *wide){
wider shape=(wider)wide;
// print same as before
}
but this still doesn't work. what am I doing wrong?