代码:
struct company_struct
{
company_name_t company_name;
double stock_price;
company_stock_t company_stock;
};
typedef struct company_struct company_struct_t;
int sort_by_price(const void * ptr1, const void * ptr2)
{
assert(ptr1 != NULL);
assert(ptr2 != NULL);
const company_struct_t * ptr1_price = (const company_struct_t *) ptr1;
const company_struct_t * ptr2_price = (const company_struct_t *) ptr2;
assert(ptr1_price->stock_price != NULL); //??? Why it failed?
assert(ptr2_price->stock_price != NULL);
if(ptr1_price->stock_price > ptr2_price->stock_price) return -1;
else if (ptr1_price->stock_price == ptr2_price->stock_price) return 0;
else if (ptr1_price->stock_price < ptr2_price->stock_price) return 1;
}
qsort(company_list, *size, sizeof(company_list), sort_by_price);
当我运行我的程序时,断言失败了。我对C比较陌生,请多多包涵。