Let's assume that the structure is called card and c1 and c2 are two pointers to objects of the structure.
In this case you should use the following condition to compare elements of the array
int comparison( card *c1, card *c2 )
{
int color_cmp = strcmp( c1->color, c2->color );
return color_cmp < 0 || ( color_cmp == 0 && c1->rank < c2->rank );
}
This predicate is considered as a boolean predicate. If you need a comparison function thet will be used in the standard algorithm qsort then you have to change it such a way that it returns -1, 0 or 1.
For example
int comparison( const void *p1, const void *p2 )
{
const card *c1 = ( const card * )p1;
const card *c2 = ( const card * )p2;
int color_cmp = strcmp( c1->color, c2->color );
if ( color_cmp < 0 )
{
return -1;
}
else if ( color_cmp > 1 )
{
return 1;
}
else
{
return ( c2->rank < c1->rank ) - ( c1->rank < c2->rank );
}
}
color1 < color2, you can change that tocolor1 < color2 || (color1 == color2 && rank1 < rank2).