У меня есть программа, которая пытается отсортировать некоторые имена в алфавитном порядке. Я запускаю его, и он не имеет никаких ошибок, но имена не отсортированы. Я сравниваю 2 имени и вижу, какое из них должно быть смещено в массиве.
Вот код:
void sort_names(char array[])
{
const int arraysize = 5;
// Step through each element of the array
for (int startindex = 0; startindex < arraysize; startindex++)
{
int smallestnum = startindex;
for (int currentindex = startindex + 1; currentindex < arraysize; currentindex++)
{
// If the current element is smaller than our previously found smallest
if ((student_list[currentindex].lname) < (student_list[smallestnum].lname))
// Store the index
smallestnum = currentindex;
}
// Swap our start element with our smallest element
swap(student_list[startindex], student_list[smallestnum]);
}
}
Моя структура выглядит так:
struct student {
char fname[30];
char lname[30];
};
Нужно ли где-то преобразовывать их в строки, потому что они являются массивами символов? Я немного растерялся и пытаюсь понять, как сделать так, чтобы все было правильно.