Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. void Vector_set(Vector *vector, size_t index, const char *str) {
  2. // char * temp;
  3. // Perform safety asserts
  4. assert(vector);
  5. assert(str);
  6. assert(index >= 0);
  7.  
  8. // If there's currently something at the vector in that spot, we'll override it.
  9.  
  10. /*
  11. if(vector->array[index]) {
  12. free(vector->array[index]);
  13. vector->array[index] = NULL;
  14. }
  15.  
  16. // Perform the copy
  17. vector->array[index] = malloc(strlen(str)+1);
  18. */
  19.  
  20. if(vector->array[index]) {
  21. vector->array[index] = (char *) realloc(vector->array[index], strlen(str)+1);
  22. }
  23. strcpy(vector->array[index], str);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement