Add function to access element by index.
This commit is contained in:
@@ -103,3 +103,12 @@ int vec_foreach(vec* v, void* data, compare_func compare, foreach_func foreach,
|
||||
}
|
||||
return return_code;
|
||||
}
|
||||
|
||||
void* vec_index(vec* v, int index){
|
||||
void* to_return = NULL;
|
||||
if(index < v->capacity && index >= 0) {
|
||||
void** data_array = v->data;
|
||||
to_return = data_array[index];
|
||||
}
|
||||
return to_return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user