Advertisement
oaktree

what does this do?

Nov 4th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. void some_function(char*** arr, const char* s, size_t *arr_len) {
  2.     if (*arr == NULL) {
  3.  
  4.         *arr = malloc(sizeof(char*));
  5.         (*arr)[0] = strdup(s);
  6.         *arr_len = 1;
  7.         return;
  8.     }
  9.  
  10.     char** tmp;
  11.     if ( (tmp = realloc( *arr, (*arr_len + 1) * sizeof(char*) )) == NULL) {
  12.         perror("couldnt get more memory.");
  13.     }
  14.  
  15.     *arr = tmp;
  16.     (*arr)[(*arr_len)++] = strdup(s);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement