我在结构内的选择类型的字符串方面遇到问题。我输入的所有值在排序后都不会改变位置。我认为我遗漏了一些小东西,但我无法在互联网上找到相关帮助。*p_customer_start
指向数组的开头。p_outer
并且p_inner
应该进行排序。有谁知道出了什么问题?
void sort_customers(int quantity, struct customer *p_customer_start)
{
struct customer *p_customer,
*p_outer,
*p_inner,
temp_customer;
printf("\nInside the sorting function.");
for(p_customer = p_customer_start; (p_customer-p_customer_start) < quantity; p_customer++)
{
p_inner = p_customer;
for(p_outer = p_customer + 1; p_outer <= quantity; p_outer++)
if(strcmp(p_outer->customer_name, p_inner->customer_name) > 0)
p_inner = p_outer;
temp_customer = *p_customer;
*p_customer = *p_inner;
*p_inner = temp_customer;
p_inner++;
}
return;
}