I have an array of structs (actually it's a heap array sorted by priority).
typedef struct {
char name[MAX_CHARACTERS+1];
int priority;
} person;
person p[MAX_HEAPSIZE+1];
and want to remove the first element in the array. I'm not sure how or what command to use.
So far, I've been doing
void remove(){
swap(0, heapsize-1);
strcpy(p[heapsize-1].name, p[MAX_HEAP_SIZE+1].name);
p[heapsize-1].priority = p[MAX_HEAP_SIZE+1].priority;
}
this swaps the first and last non-empty element in the array. Then it tries to copy the data at an empty element to the last non-empty element (element i want to remove) in the array.
but I think it only copies the memory positions. Is there something simple where I can do
p[0] = NULL?
p[0] = (person){"anonymous", 42};or, maybe more to your liking:p[0] = (person){"", 0};otherwise you need to set each structure member separately:p[0].name[0] = 0; p[0].priority = 0;