'Remove an element from array of structs with pointers

I have to implement the appointmentData_remove function which removes an element of type tAppointment from the tAppointmentData array.

Data types are defined like this:

// Type that stores a vaccination appointment data
typedef struct _tAppointment {    
    tDateTime timestamp;
    tPerson* person;
    tVaccine* vaccine;
} tAppointment;

// Type that stores a list of vaccination appointments
typedef struct _tAppointmentData {    
    tAppointment* elems;
    // Number of elements
    int count;    
} tAppointmentData;

typedef struct _tPerson {
    char* document;
    char* name;
    char* surname;
    char* cp;
    char* email;
    char* address;
    tDate birthday;
} tPerson;

typedef struct _tVaccine {
    char *name;
    int required;
    int days;
} tVaccine;

typedef struct _tDate {    
    int day; 
    int month;
    int year;
} tDate;

typedef struct _tTime {
    int hour; 
    int minutes;
} tTime;

typedef struct _tDateTime {
    tDate date;
    tTime time;    
} tDateTime;

The function should check if a certain condition meets in order to find the index of the element to remove. So far I have developed the following but the only result i get is a decrement on count but I can't get the elements to shift to the right position.

void appointmentData_remove(tAppointmentData* list, tDateTime timestamp, tPerson* person) {

int i, j;
    
    i = 0;
    j = 0;

    for (i=0;i<list->count;i++) {
        if (condition) {
            j = i;
            for (i=j;i<list->count;i++) {
                list->elems[i].person = list->elems[i+1].person;
                list->elems[i].vaccine = list->elems[i+1].vaccine;
                list->elems[i].timestamp = list->elems[i+1].timestamp;
                }
        list->count --;
        }
    }
}

For example if the element to delete is at index 0 I understand that it should be replaced with the element 1, and index 1with index 2, etc.. but for some reason the loop isn't working. Any thoughts?? Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source