Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit #15

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ If you finish these goals, try implementing some of the other Python functions:
7. `sort()`

Check the official documentation or use Python's `help()` method for implementation details.
https://github.com/LambdaSchool/Arrays/pull/15



Expand Down
14 changes: 11 additions & 3 deletions arrays/arrays.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,31 @@ typedef struct Array {
*****/
Array *create_array (int capacity) {
// Allocate memory for the Array struct
Array *new_arr = malloc(sizeof(Array));

// Set initial values for capacity and count
new_arr -> capacity = capacity;
new_arr -> count = 0;

// Allocate memory for elements
new_arr -> elements = calloc(capacity, sizeof(char*));

return new_arr;
}


/*****
* Free memory for an array and all of its stored elements
*****/
void destroy_array(Array *arr) {

for(int i = 0; i<arr->count; ++i){
// Free all elements

free(arr -> elements[i]);
}
// Free array

free(arr->elements);
free(arr);
arr = NULL;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious as to why you have this line here. What purpose does it serve?

}

/*****
Expand Down