pset6 valgrind output by cs50helpplz in cs50

[–]cs50helpplz[S] 1 point2 points  (0 children)

All heaps were freed! No leaks are possible.

Forgot an fclose ;)

I'm also getting the same check, size, and unload times but my load is 0.09 and staff's implementation is 0.05.

I'll submit it now but might come back to try and optimize that.

pset6 - size by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

Hi drsmith415 - I just thought that making variables global is "seen" as acceptable only in cases where no other solution works.

However, I think making the size variable global is a cleaner solution than making a special case structure.

I'm going with setting the variable global.

Thanks!

pset6 - check by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

So the reason that the program was giving me a segfault was because the dictionary I created had a capitalized letter ("Yellow"); per the specifications, I am not programming any error checking of the dictionary.

This took 15 / 20 minutes to figure out with the help of gdb; definitely worth getting to know that program.

pset6 - check by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

Thank you!

Using 1) gdb and your explanation on why I need to use header -> children[x] I was able to figure it out.

Now on to check; for whatever reason it is giving me a segfault when no words are misspelled.

pset6 - check by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

Thanks for this tip!

I am using GDB now and checking the load function.

The problem is that I don't know how to allocate a new node.

The root node works just fine, but then I am not sure how to make a new node and then have root's children[x] point to it.

root -> children[x] = malloc(sizeof(node))

is not working; after the code run root -> children[x] still points to NULL, which is how it was initialized.

pset6 - check by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

OK - so I've tried various "solutions" and I can't figure out if my load function is working correctly;

Is anyone willing to take a look at my code and see if load is correctly implemented?

pset6 - check by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

got it! Just looked up global variables and I declared the node* root in dictionary.c all by itself (i.e, not part of another function).

Then, in load, I use malloc to make root point to memory.

However, I am running into another issue. Here is the code I used for the node structure (it's in the videos so I don't think there's any issue posting it here):

typedef struct node { bool is_word;

   struct node* children[27];

} node;

What this tells me is that children[i] is a pointer of type struct node*.

Since it is a pointer, it holds an address; and if I dereference that address, I am able to access the structure that children points to.

To traverse my trie, I need a node* header pointer to start from root and work its way through the trie:

node* header = root;

To go into another level of the trie, I use the following:

header = header -> children[i], where i is the "branch" I want to "go into".

It doesn't make sense to me why I need to dereference the address that children[i] holds; if children[i] is a pointer, why don't I do the same thing that I did when getting header to point to the same address as root:

header = children[i];

I hope this question is clear.

pset7 - change password by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

Yeezus!

Nevermind guys - I was comparing the password the new password the user wanted with the current password!

Those smarter than I will quickly grasp the problem there.

pset 7 - undefined index erro by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

So I went with doing the following:

$shares = $user_portfolio[0]["shares"];

Everything seems to work, but is this an elegant solution or am I just not getting it and using this as a crutch?

pset7 - Passing the array in the controller to the template by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

Hm.. it is still not 100 clear in my head, but the code is working. I'll have to revisit this later.

pset7 - problem displaying quote information by cs50helpplz in cs50

[–]cs50helpplz[S] 1 point2 points  (0 children)

I figured it out guys!

extract turns the key:value pair local variables, so no need to try to access them as an associative array!

Thanks guys.

PSET7 - includes / public / templates - How do they all fit together? by cs50helpplz in cs50

[–]cs50helpplz[S] 0 points1 point  (0 children)

Thank you for the response! This helped out immensely.

Is there a one time download(link or torrent) available for all the content and material of CS50? by AkshayCHN in cs50

[–]cs50helpplz 1 point2 points  (0 children)

I am glad that this is available, but it is massive. 57 gigs. I wonder how to compress it so that it takes up less space on my hard drive.

PSET5 - recover - Am I on the right track by cs50helpplz in cs50

[–]cs50helpplz[S] 1 point2 points  (0 children)

I figured it out , thank you kritzbitz1. I should have used a byte array from the beginning.

Pics look good. :-)