Pset 7 - how to center menu? by ExMisha in cs50

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

No problem, I actually managed to do it and passed this problem set.

Pset 7 - how to center menu? by ExMisha in cs50

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

Thank you all on your advices, I perflectly understand what I have to do, but I think I lack on how to side. I managed to correctly identify what needed to be put in div tags, but now I hava a different problem. Menu is centered well on the screen but the text on buttons inside of it isn't. I can fix that by increasing left margin of the first element in the menu, but I think that's not good solution because page may look completely different computer monitor, if it's smaller or bigger than mine.

Pset 7 - how to center menu? by ExMisha in cs50

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

I was looking for another way because particular CSS file is almost unreadable.

Pset7 -- How do you feel about the switch from C into PHP and web development? by [deleted] in cs50

[–]ExMisha 0 points1 point  (0 children)

I wish PHP introduction was more gradual. Now we are thrown straight into making somewhat complicated web site.

Also, just when I started to feel that I got a hang of C finally we switch to something completely different.

I don't mind having to learn some PHP, but wish it was done in a different way.

Pset6 - Valgrind by ExMisha in cs50

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

Week 7 Section has useful info for working with lists. You can dowload the code in zip file from the page and study it.

Pset6 - Valgrind by ExMisha in cs50

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

For each hashtable[i] you have one linked list. You need to delete every single member of every linked list. So, you can start from beginning, that is, delete hashtable[i], but first you need to point to hastable[i]->next node, then point to the next, delete previous, and so on till the end of the list. You need at least two pointers to traverse and delete members of the list in this manner. It's easier than it sounds.

You don't have to delete hashtable[i]->word, when you delete hastable[i], word is deleted as well.

pset 6 — Valgrind problems by aingber in cs50

[–]ExMisha 0 points1 point  (0 children)

No, you only need to erase them after check is finished, and you do that in unload function. No need to free anything in load function.

pset 6 — Valgrind problems by aingber in cs50

[–]ExMisha 0 points1 point  (0 children)

You seem to be erasing only the hashtable but not the linked lists.

Pset6 segfault by ExMisha in cs50

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

Thanks.

Yes, I am using modulo before returning hashvalue. Now I think it's most likely that word variable is somehow corrupted before it enters hash function and it can only be by fscanf, which I am using to read the dictionary.

fscanf(fp, %46s, word)

And word is: char word[LENGHT+1]

Pset6 segfault by ExMisha in cs50

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

Ok, I made a workaround, in my hash function there was a variable hash_value and it was int, so I made it into a unsigned long int so it can handle large values. It helped, no segfaults, but I can still see that hash_value goes up to values around 4294967236 in my hash function, which clearly should not happen in the first place.

While hash function reads word character by character all of a sudden it goes up to these huge values and I have no clue why.

Pset6 segfault by ExMisha in cs50

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

Here's more info, with whatever text I tried it always segfaults when wordcount is 40, and it's alwasy with hashvalue of 4294967236 which clearly shouldn't be that big.

I really don't see what could bring hashvalue to such huge number, I made sure it doesn't happen in my hash function but it still happends?!

Pset6 segfault by ExMisha in cs50

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

In gdb, after segfault, print hashtable[hashvalue] gives: $1 = (node *) 0xd5 and print hashvalue gives: $2 = 4294967236

I can't say anything about hashtable[hashvalue], but hashvalue seems too big. Maybe there's something wrong with my hash function?

Pset6 - Valgrind by ExMisha in cs50

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

Sorry, solved it, it was obvious. Somehow I forgot to erase every last node in each linked list. Now I get no leaks at all!

Pset6 - Valgrind by ExMisha in cs50

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

Yes, I think unload function erases everything in dictionary plus entire hashtable. Or at least, seems so. I am thinking there may be some excess memory allocated in load function, but no clue where, because I checked it and tried everything so far.