I use qsort and first I compare by b. Since b is a number they can be same and if they are I would like to compare those two items by their a also. Can I do that?
Yes, because the string "15" is less than the string "2".
If you want to sort on numerical value, you'll have to convert to int first.
1 2 3 4 5 6 7 8
int compare(constvoid *a, constvoid *b)
{
struct s *ia = (struct s *)a;
struct s *ib = (struct s *)b;
int av = atoi( ia->a ); // string MUST be convertible to int!
int bv = atoi( ib->a ); // string MUST be convertible to int!
return av - bv;
}
Notice the caveat in there about the strings in s::a being convertible to int. If it is a possibility that they are not convertible, then use strtol() instead. See the documentation for both for more.