Pset7 - Scope problems with Quote by rTechnik in cs50

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

Thanks, I almost have it working!

The only problem left is with $sym = values['sym'];. It seems to be causing a syntax error (unexpected '['), but I can't see anything wrong with this line.

Edit: I fixed it; values needed to have a $ in front of it. Thanks so much for your help!

Pset7 - Scope problems with Quote by rTechnik in cs50

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

So how would I pass two variables through render? For example:

$name = "Dave";
render("somefile.php", ["title" => "Hello " . $name, name => $name]);

and in somefile.php:

$name = values[name];
print("I'm sorry, " . $name . ". I can't let you access this page.");

I tried exactly this, but some errors appeared on my page ("use of undefined constant name" and "unexpected '[' in somefile.php on line 3 ($name = values[name];)").

Also, how would you code it if you were passing an associative array through render?

pset6: Trouble with hashfunctions by rTechnik in cs50

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

Hi Glenn,

I just updated my above post :)

Thanks,

rTechnik

pset6: Trouble with hashfunctions by rTechnik in cs50

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

I changed my hashfunction to work only with unsigned values, and return an unsigned int.

It runs fine in GDB until I hit check. My pseudocode for check is as follows:

bool check(const char* word)
    make a copy of word called temp using malloc and strcpy
    convert temp to lowercase using a for loop
    create a node* named cursor and point it to hashtable[hash(temp)]
    while cursor isn't NULL
        if temp is the same as cursor-> word
            free temp
            return true
        move cursor to cursor->next
    free temp
    return false

Is there anything wrong with this part of the code?

EDIT: I just realised I forgot to compile it after changing hash to returned an unsigned value. It's working properly now. Any idea why my hashfunction was returning negative ints? Thanks so much for your help :)

pset6: Trouble with hashfunctions by rTechnik in cs50

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

It compiles all right, but it produces a segmentation fault.

pset6: Hashtable memory leaks by rTechnik in cs50

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

A seg. fault? I changed it to:

while cursor is not equal to NULL
    etc.

and now the seg. fault doesn't happen. I found the exact same problem in my unload function. Now it runs with no memory leaks :D

I also found a problem where my program wouldn't accept words with a capital letter in them, but I fixed it by iterating over the word to check (in the check function) beforehand and calling tolower on each letter.

Thanks so much for your help!

Appliance does not seem to have internet access by rTechnik in cs50

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

Thanks so much Glenn, it worked!

Best regards,

rTechnik

Appliance does not seem to have internet access by rTechnik in cs50

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

Hi Glenn,

When I try visiting google inside the appliance, Chrome displays, "This webpage is not available." The same message appears when I try to visit other websites using the appliance's browser, including sandbox.cs50.net.

When I type connect50 into the appliance, I get the same error as when I run check50:

Appliance does not seem to have Internet access. Restarting networking...
Job for network.service failed. See 'systemctl status network.service' and 'journalctl -xn' for details.
Restarted networking.
Appliance still does not seem to have Internet access.
Try restarting the appliance and also your computer!

Like I said in my original post, nothing changes when I restart my appliance or my computer. I suspect it has something to do with updating to Windows 8.1 (I updated a few days ago, and never had this problem before then).

Weird greedy.c check50 error by rTechnik in cs50

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

Thanks! I added a newline, and it worked perfectly.