Skip to content

Commit

Permalink
Include cleanup function for readlines
Browse files Browse the repository at this point in the history
  • Loading branch information
muppet2011ad committed Jun 22, 2021
1 parent 7f5df7b commit c93f316
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions readlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ char **read_lines (FILE* src, char ***lines, int *num_lines, int *lines_arr_size
(*num_lines)++; // Increment the counter of items in the array
}
return *lines; // Return a pointer to the array
}

void destroy_lines(char **lines, int num_lines) {
for (int i = 0; i < num_lines; i++) {
free(lines[i]);
}
free(lines);
}
1 change: 1 addition & 0 deletions readlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
#define LINES_ARR_LEN 8

char **read_lines (FILE* src, char ***lines, int *num_lines, int *lines_arr_size);
void destroy_lines(char **lines, int num_lines);

#endif

0 comments on commit c93f316

Please sign in to comment.