int id_swap()
{
char tempstring[15];
strcpy(tempstring, id[index+1]);
strcpy(id[index+1], id[index]);
strcpy(id[index], tempstring);
}
int delete_student()
{
int found=0;
char id_to_find[10];
printf("Please enter the student ID to delete\n\n");
scanf("%s", & id_to_find);
fflush(stdin);
system("cls");
for(index=0;index<height_of_array+1;index++)
{
if(strcmpi(id_to_find, id[index]) == 0)
{
found=1;
id_swap();
system("cls");
printf("Student deleted");
height_of_array = height_of_array--;
}
Okay so that’s part of my code. A quick example of what happens
I sort the students that are already in the program so it comes up like this for e.g
Student#1 Chris ID: 1831
Student#2 etc
student#3 etc
student#4 Brian ID: 4432
student#5 etc
student#6 etc
But when I try to delete say Brian for example, it deletes it but then it looks like this
student#1 ID:
Student#2 Chris ID:1831
Student#3 etc
Is there any way to move that blank array to the last position so I can then decrement my “Height_of_array” so that the number of storable students goes down by 1 to reflect the deletion
There are a few problems with your code: that jump at me:
Never do that. Only flush output streams.
Is undefined behavior, you meant: