Answers for "/*** copy new_val in the array at index v->no_e ***/"

0

/*** copy new_val in the array at index v->no_e ***/

void v_push_back(vector_type v, void* new_val){

if( v->no_e >= v->cur_cap ){

    /*** reallocate a larger array ***/
    v->cur_cap += (v->cur_cap) ? v->cur_cap : 2;

    v->e_array = realloc(v->e_array, v->cur_cap*(v->e_sz))

}
/*** copy new_val in the array at index v->no_e ***/

/*** TO BE DONE START ***/

if(v->e_type == 1)
    memcpy(((int*)v->e_array) + v->no_e*(v->e_sz), new_val, v->e_sz);
else if(v->e_type == 2)
    memcpy(((double*)v->e_array) + v->no_e*(v->e_sz), new_val, v->e_sz);
else if(v->e_type == 3)
    memcpy(((char*)v->e_array) + v->no_e*(v->e_sz), new_val, v->e_sz);
else if(v->e_type == 4)
    memcpy(((float*)v->e_array) + v->no_e*(v->e_sz), new_val, v->e_sz);

/*** TO BE DONE END ***/

(v->no_e)++;
}
Posted by: Guest on April-08-2022

Browse Popular Code Answers by Language