Woking
Woking

Reputation: 1

Copy a struct array to another struct array that is smaller

My struct array has 5 slots

struct router* router[5];

Lets say there are elements inside them, and then i make

router[3] = NULL;

Is it possible to rearrange the array so that the element in router[4] moves up to router[3], router[5] moves to router[4] etc.?

Upvotes: 0

Views: 62

Answers (1)

Ben Wainwright
Ben Wainwright

Reputation: 4621

Try this

void delete(struct router** router, int which, int size) {
    int i;
    // If these pointers have no other references to them then
    // Then you should free the one being deleted at this point
    for(i = which; i < size - 1; i++) {
       router[i] = router[i + 1];
    }
    router[i] = NULL;

}

Upvotes: 1

Related Questions