Do not increase students
before you call addStudents
.
Otherwise it is out of the bounds of the array (and are editing a different student).
students++;
ptr = realloc(ptr, students * sizeof(struct student));
addStudents(ptr, students);
Should be
ptr = realloc(ptr, (students + 1) * sizeof(struct student));
addStudents(ptr, students);
students++;