I would advise you to rebuild your program. Instead of storing two independent arrays for names and identifiers, you can save one array of structures that contain all the necessary data:
typedef struct student { int id; char name[MAX_NAME_LENGTH]; } student_t; student_t students[ARRAY_SIZE];
Now you have one array that can never become "inappropriate", sorting identifiers without names, etc.
You can sort the array in C using the standard qsort() library function:
qsort(students, ARRAY_SIZE, sizeof(student_t), comparator);
This requires a comparator definition, which is quite simple. One example would be:
int comparator(const void *lhs, const void *rhs) { const student_t *s1 = lhs, *s2 = rhs; return s1->id - s2->id; }
You can use the same comparator with another standard library function bsearch() to search for an array of students after sorting it:
student_t key = { 42 };
These standard features are more efficient than what you had and require you to write much less code with less chance of errors.
source share