Answer the question
In order to leave comments, you need to log in
How to insert an element at a specific place in a vector in C?
Good afternoon. There is a dynamic array implemented using vector in C.
int vector_push_back(vector_t *v, const void *item) {
if (!v || !item) {
return 0;
}
if (v->count == v->capacity) {
if (!vector_realloc(v, v->capacity * VECTOR_SIZE_MULT)) {
return 0;
}
}
memcpy((void *)((char *)v->data + (v->count * v->item_size)), item, v->item_size);
v->count++;
return 1;
}
This is the function of adding a new element. How can I make it so that I can insert new elements at a specific location in an array using an index? Thanks
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question