struct if1
{
string idnum;//id number for the student
string lastname;//last name of student
string firstname;//first name of student
int examscore[maxexam];//array of all the exam scores of the student
int hwscore[maxhw];//array of all the home work scores of the student
};
void alphasort(if1 student[], int n)
//the alphasort function will sort the records into alphabetical order by last name. It expects the list as well as the total number of
//names and will return the sorted array. The basic format for this function came from the class handout on bubblesorting.
{
if1 temp;//used as a swapping mechanism
int i; int j;// used for implementing for loop checks
int f=1;//used for checking letters after the first
for (i=0; i < n-1; i++)
for (j=0; j < n-(i+1); j++)
if(student[j].lastname[0] > student[j+1].lastname[0])
{
temp = student[j];
student[j] = student[j+1];
student[j+1] = temp;
}
else if(student[j].lastname[0] == student[j+1].lastname[0])
{
while(student[j].lastname[f] == student[j+1].lastname[f])
{
f++;
}
if (student[j].lastname[f] > student[j+1].lastname[f])
{
temp = student[j];
student[j] = student[j+1];
student[j+1] = temp;
}
}
}
im new here, so i hope i didnt post in the wrong area or something...
using an array of structs this function does not work, while the same function using only a simple array of strings does work properly.
i cant figure out why there would be any difference.
the array of structs will not sort alphabetically using all letters in the name if necessary while the simple array will sort 100% correct.
any ideas?