Skip to content

Arrays-Sumi#74

Open
sumi419 wants to merge 4 commits into
bloominstituteoftechnology:masterfrom
sumi419:master
Open

Arrays-Sumi#74
sumi419 wants to merge 4 commits into
bloominstituteoftechnology:masterfrom
sumi419:master

Conversation

@sumi419
Copy link
Copy Markdown

@sumi419 sumi419 commented Feb 25, 2019

No description provided.

Comment thread arrays/arrays.c Outdated
for (int i = 0; i < arr->count; i++)
{
arr->elements[i] = NULL;
free(arr->elements[i]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job looping through these elements and freeing them one by one.

Comment thread arrays/arrays.c
arr->capacity = capacity;
arr->count = 0;
// Allocate memory for elements
arr->elements = malloc(capacity * sizeof(char *));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can also use calloc here.

Comment thread arrays/arrays.c
// Throw an error if the index is greater than the current count
if (arr->count < index)
{
printf("Index is higher that current count.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice error message 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants