Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. typedef struct vector_ {
  2. void** data;
  3. int size;
  4. int count;
  5. } vector;
  6.  
  7. void vector_add(vector*, void*);
  8. void vector_add(vector *v, void *e)
  9. {
  10. if (v->size == 0) {
  11. v->size = 10;
  12. v->data = malloc(sizeof(void*) * v->size);
  13. memset(v->data, '', sizeof(void*) * v->size);
  14. }
  15.  
  16. if (v->size == v->count) {
  17. v->size *= 2;
  18. v->data = realloc(v->data, sizeof(void*) * v->size);
  19. }
  20.  
  21. v->data[v->count] = e;
  22. v->count++;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement