Aquí te dejo una versión que acabo de hacer simplificada para que veas la parte del ordenamiento. Lo que hay que hacer una vez se tienen los alumnos con sus respectivos nombres y apellidos, se comparan los apellidos del padre y el que sea menor se pone primero; si son iguales, se compara el de la madre y el menor se pone primero; y si son iguales, se comparan los nombres y el primero se pone primero.
Si tienes dudas sobre el valor de retorno de <strcmp> es el siguiente:
< 0 si la primera cadena es menor que la segunda.
> 0 si la primera cadena es mayor que la segunda.
= 0 si las dos cadenas son iguales.
Adapta esto a tu programa. Suerte.
#include <stdio.h>
#include <string.h>
#define TAM 20
#define MAX_STUDENTS 3
typedef struct{
char name[TAM];
char lastNameFather[TAM];
char lastNameMother[TAM];
} Student;
void initializeStudent(Student*, char*, char*, char*);
void showStudent(Student);
void sortStudents(Student*);
int main(){
Student st1, st2, st3;
initializeStudent(&st1, "aaaa", "baba", "cccd");
initializeStudent(&st2, "aaaa", "abab", "cccc");
initializeStudent(&st3, "aaab", "baba", "cccc");
Student students[MAX_STUDENTS] = {st1, st2, st3};
puts("Alumnos sin ordenar"); for(size_t i = 0; i < MAX_STUDENTS; i++)
showStudent(students[i]);
sortStudents(students);
puts("\nAlumnos ordenados"); for(size_t i = 0; i < MAX_STUDENTS; i++)
showStudent(students[i]);
}
void initializeStudent(Student *st, char *name, char *lastNameFather, char *lastNameMother){
strncpy(st
->lastNameFather
, lastNameFather
, TAM
); strncpy(st
->lastNameMother
, lastNameMother
, TAM
); }
void showStudent(Student st){
printf("%s\t%s\t%s\n", st.
lastNameFather, st.
lastNameMother, st.
name); }
void sortStudents(Student *students){
Student assistant;
for(size_t i = 0; i < MAX_STUDENTS-1; i++){
if(strcmp(students
[i
].
lastNameFather, students
[i
+1].
lastNameFather) > 0){ assistant = students[i];
students[i] = students[i+1];
students[i+1] = assistant;
}
else if(strcmp(students
[i
].
lastNameFather, students
[i
+1].
lastNameFather) == 0){ if(strcmp(students
[i
].
lastNameMother, students
[i
+1].
lastNameMother) > 0){ assistant = students[i];
students[i] = students[i+1];
students[i+1] = assistant;
}
else if(strcmp(students
[i
].
lastNameMother, students
[i
+1].
lastNameMother) == 0){ if(strcmp(students
[i
].
name, students
[i
+1].
name) > 0){ assistant = students[i];
students[i] = students[i+1];
students[i+1] = assistant;
}
}
}
}
}