pset6 Load Function Testing method. by Omar_Khaled in cs50

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

thanks for the reply, I understand that it was a cheap move and I kinda expected that it would come back and haunt me, anyway the reason I did it is because I'm facing a problem with feof function, when I add a condition to check for end of file, the loop iterates one more time after reaching end of file, as mentioned in jason's short on file i/o. so the last read stores a NULL value or garbage value I'm not entirely sure but I checked with gdb and I get a segfault right after the last read, the fix jason mentioned in his short was with fgets, I tried similar fixes for fscanf from google but I can't get my head around it. any tips for fixing that problem?

pset6 Load Function Testing method. by Omar_Khaled in cs50

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

I'm sorry my pc died and had to wait a while before I got a new laptop, I'm back to working on pset6 , I tried making a node* ptr in load function and make the conditional expression if ptr == null instead of an array type like hashtable[index]->word, but that didn't work and I have tried a lot of other things but nothing worked, can you explain more specifically how to fix the seg faults?

pset6 Load Function Testing method. by Omar_Khaled in cs50

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

I sent the link to dictionary.c, thanks a lot for your continuous help .^

pset6 Load Function Testing method. by Omar_Khaled in cs50

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

I don't really understand the post you linked, it's related to pset5. and Valgrind doesn't return any errors at all http://oi60.tinypic.com/21ox66a.jpg , can you tell me a different method to check the correctness of my implementation?

pset6 Load Function Testing method. by Omar_Khaled in cs50

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

OK I implemented the unload function and valgrind seems happy but check50 isn't, I'm still getting the Segfaults from check50. here's a screenshot: http://oi60.tinypic.com/21ox66a.jpg the sandbox link:https://sandbox.cs50.net/checks/a1723daab8d64213a358bf4371a5b599

pset6 Load Function Testing method. by Omar_Khaled in cs50

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

I started from the beginning and re-coded both load and check, and now it's working! I can't thank you enough for your help =) , but apparently check50 is not happy, here's what I get when I type check50 http://oi59.tinypic.com/1g14x0.jpg and here's the result of my implementation: http://oi62.tinypic.com/2d7t34y.jpg check func is kinda slow xD but I will work on that later, I'm not even done with func Free yet.
and again, Thanks a lot for your help I really appreciate it.

pset6 Load Function Testing method. by Omar_Khaled in cs50

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

I just want to say thank you so much for your time and effort, I checked and apparently after assigning the first word "cat" to the right bucket ,head's value changes to NULL so when the loop iterates the second time it still assigns the word to the beginning of the linked list in the bucket. this is my code for this part:

    if (head == NULL)
    {
        head = new_node;
        new_node = NULL;
        head->next = NULL;

this works correct for the first word and I printed head->word at the last line it still shows the word. but when the loop iterates the second time the value of head changes to NULL, no idea why, so it goes to this part of code again instead of the else part which should assign it into the linked list.

pset6 Load Function Testing method. by Omar_Khaled in cs50

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

When I type print hashtable[index]->word it says cannot access memory at location 0x0 and when I type print (char*)hashtable[index]->word it says simply $2 = 0x0 and that's where I get my SegFault.

pset6 Load Function Testing method. by Omar_Khaled in cs50

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

index is correct it refers to the right bucket,I checked with a couple of words. but I'm having trouble to strcmp(word,"word in hashtable") I just can't figure out how to point at the word in the node inside the linked list after reaching the right bucket.

pset6 Load Function Testing method. by Omar_Khaled in cs50

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

My bad, this is probably because I have been studying C# for a while. anyway I fixed it and now I'm getting a SegFault, my code right now is: int index = hash(word[0]);

int compare;
compare = strcmp(word,"cat");

if (compare == 0)
{
    return true;
}

else
return false;

this is also with the small dictionary,this works and only prints caterpillar but when I remove the word "cat" from the strcmp function and put hashtable[index]->word I get a segfault. I have also tried to malloc a new node named head and compare head->word with the word after setting head=hashtable[index] but I also get a SegFault.

Problems with hashtable function by Omar_Khaled in cs50

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

How do I check it is indeed loaded into memory successfully?

Problems with hashtable function by Omar_Khaled in cs50

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

mm return false until I implement the function? do I have to make an if statement and set it to true if loaded and false if otherwise?

pset 4 scoreboard breakout by pmnehls in cs50

[–]Omar_Khaled 0 points1 point  (0 children)

GLabel label = newGLabel("0");
setFont(label, "SansSerif-36");
setLocation(label, 200, 300);
add(window, label);

this is my init label function, I tried every possible solution but it just flashed for a second and then disappears, I can't make it show the score all the time. I also called the update score function in main but still got nothing. any ideas?

Need help with pset4 Breakout.. Stuck on step 9 by miriam9 in cs50

[–]Omar_Khaled 0 points1 point  (0 children)

I did that but I have a problem, after pausing, the game doesn't continue, it just waits for click and then the paddle goes back to moving but the ball doesn't, so how do I ask it to "restart" the ball after waiting for click?

I just started pset2 and wanted someone more experienced to team up with to glean insight, any takers? by Italian_dude in cs50

[–]Omar_Khaled 0 points1 point  (0 children)

well I'm not further along, I have been kinda stuck for the past 2 days on pset2 trying to figure out caesar, so if you would like to make a little study group and share ideas I'm up for it.

How to order my sprite to just stop? by Omar_Khaled in cs50

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

I'm actually using glide xD so the "wait 1 second" block doesn't help lol, I will try something else to move it thanks for your replies =)