I'm new to C, and honestly have no idea where to start with removing a particular element from an array of structures.
If you wish, you can view and copy my code in its entirety here: http://pastebin.com/Zbrm2xyL
Mostly I'm concerned with the function 'rmv_student', which is supposed to remove the struct with a matching id number from the array 'st_array' without messing with the other elements of that array after prompting the user for confirmation. Function 'rmv_student' is as follows:
void rmv_student(long id) // BROKEN
{
int i; // iterator
char response; // used to confirm deletion
for( i = 0; i < MAX; i++){
if ( st_array[i].id == id){
printf("Are you sure you want to delete %s %s, %d?\n", st_array[i].first_name, st_array[i].last_name, st_array[i].id);
puts("You will not be able to undo the deletion.");
puts("Enter 'y' to delete or 'n' to return to the main menu.");
response = getchar();
switch (response){
case 'y':
// delete
case 'Y':
// delete
case 'n':
main();
case 'N':
main();
default:
puts("Please enter 'y' or 'n'.");
rmv_student(id);
}
}
}
if ( i == MAX ){
printf("\nThere are no students with ID %d.\n\n", id);
main();
}
}
I have two questions.
Are my switch cases correct? Will this test the user's input character correctly?
How do I go about deleting the struct?
Before you ask. Yes, this is homework. As such, I'm not looking for a handout, just a point in the right direction. Any other suggestions are welcome.
Note: I am aware that I don't really need the function 'menu_test_input', but I'm leaving it for now.