void sortAlphabetically(int listLength, contactInfo* arrayOfStructs)
{
contactType temp;
for (int i = 0; i < listLength; i++)
{
if (strcmp(arrayOfStructs[i].contactName, arrayOfStructs[i+1].contactName) > 0)
{
temp = arrayOfStructs[i]; //swapping entire struct
arrayOfStructs[i] = arrayOfStructs[i+1];
arrayOfStructs[i+1] = temp;
}
}
}
最佳答案
当i == (listLength-1)
时,以下表达式无效(假设listLength
是arrayOfStructs
中元素数量的计数):
arrayOfStructs[i+1]