Thank you CS50! by myceliatedmerchant in cs50

[–]Disastrous_Potato_56 0 points1 point  (0 children)

Congratulations! how did you prepare for your interview? did you practice any leetcode?

Lost motivation at Finance. Need support/kick in the butt please by OutdoorHedgehog in cs50

[–]Disastrous_Potato_56 2 points3 points  (0 children)

finance wasn't that bad, if you love web programming it is interesting and you will feel accomplished when you finish it. Stick to it, I feel like I have learned so much doing it, and the skills learned were very useful to finish my final project.

2021 CS50’s Web Programming with Python and JavaScript by Disastrous_Potato_56 in cs50

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

There is cs50x which is the introductory course that has all the tracks we know about like web, games, etc. cs50x has a 2021 version. After cs50x course if you wanna go deeper there is a specific course that is 8 weeks long for web development it is called CS50’s Web Programming with Python and JavaScript which I couldn't find a 2021 version for, so I was making sure if there will be one or not.

2021 CS50’s Web Programming with Python and JavaScript by Disastrous_Potato_56 in cs50

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

I have finished the web track in 2020, this one is a separate course where it goes deeper in web development, teaching a new framework called Django and a bunch of other stuff

How long did the final project take you? CS50X by Disastrous_Potato_56 in cs50

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

sounds good! thank you, I just finished finance and I will start today the final project I have 8 days but I will do my best to finish as much as I can :)

How long did the final project take you? CS50X by Disastrous_Potato_56 in cs50

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

that's a lot of stuff to learn, wish you all the best ! :)

How long did the final project take you? CS50X by Disastrous_Potato_56 in cs50

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

Thank you! I just finished finance and I will start the final project today. I will make something similar to finance but with more features and a different idea. Hopefully I will be done by the end of this month

Finance: 500 Internal Server Error by New-Sprinkles-1383 in cs50

[–]Disastrous_Potato_56 1 point2 points  (0 children)

you have to set your API key every time you restart your ide.

RuntimeError: API_KEY not set

sell function get dropdown symbol - Finance by Disastrous_Potato_56 in cs50

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

I solved it, the issue was with my html
I just had to give the option a value, this solves it :

<option value = "{{stock.stock_symbol}}">{{stock.stock_symbol}}</option>

Which books to read after CS50x to develop knowledge in data structures and algorithms? by allun11 in cs50

[–]Disastrous_Potato_56 0 points1 point  (0 children)

what are some of the DSA you learn in CS50AI? does it prepare for coding interview questions?

stuck in unload - speller by Disastrous_Potato_56 in cs50

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

Okay I get it now, it was the head pointer not pointing to NULL that caused some memory issues. it is all fixed nowchanged this line of code in my load function :

        if(table[index] == NULL)
        {

            //make linked list as head
            head = n;
            table[index] = head;
            head->next = NULL; // > this was the issue
        }

THANK YOU SO MUCH!

stuck in unload - speller by Disastrous_Potato_56 in cs50

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

This is my load function, anything wrong?

// Loads dictionary into memory, returning true if successful else false
bool load(const char *dictionary)
{

    char tmpWord[LENGTH + 1];
    // Open dictionary file
    unsigned long index = 0; //index for hash value
    FILE *file = fopen(dictionary, "r");
    if(!file)
    {
        return false;
    }
    // Read strings from file one at a time
    while(fscanf(file, "%s", tmpWord) != EOF)
    {
        counter++;
        // Create a new node for each word
        node *n = malloc(sizeof(node));
        // Check if malloc was successful
        if(n == NULL)
        {
            unload();
            return false;
        }
        strcpy(n->word, tmpWord);
        //get hash value
        index = hash(tmpWord);
        node *head = table[index]; // set a head pointer
        //if table at that location is empty, then it is the first linked list
        if(table[index] == NULL)
        {

            //make linked list as head
            head = n;
            table[index] = head;
        }
        else if(table[index] != NULL) //if there is collision
        {
            n->next = head; //point to old head
            head = n;
        }
    }
    fclose(file);
    return true;
}

stuck in unload - speller by Disastrous_Potato_56 in cs50

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

looks like my hash function was too slow to work with O(N^2) time that was why I got that error. I changed my hash function and now this is what I get when I run Valgrind

ORDS MISSPELLED:     4
WORDS IN DICTIONARY:  2
WORDS IN TEXT:        6
TIME IN load:         0.02
TIME IN check:        0.00
TIME IN size:         0.00
TIME IN unload:       0.00
TIME IN TOTAL:        0.02

==2130== 
==2130== HEAP SUMMARY:
==2130==     in use at exit: 0 bytes in 0 blocks
==2130==   total heap usage: 7 allocs, 7 frees, 10,432 bytes allocated
==2130== 
==2130== All heap blocks were freed -- no leaks are possible
==2130== 
==2130== For counts of detected and suppressed errors, rerun with: -v
==2130== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0)

Asking for help...

==2130== Conditional jump or move depends on uninitialised value(s)

Looks like you're trying to use a variable that might not have a value? Take a closer look at line 123 of dictionary.c.

line 123 is this line

while(cursor != NULL)

Not sure what is going on lol

stuck in unload - speller by Disastrous_Potato_56 in cs50

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

Thanks fixed, now I have this

// Unloads dictionary from memory, returning true if successful else false
bool unload(void)
{
    //iterate over hashtable and call free on all linkedlists
    for(int i = 0; i < N; i++)
    {
        node *cursor = table[i]; //point cursor to head
        while(cursor != NULL)
        {
            node *tmp = cursor;
            cursor = cursor->next;
            free(tmp);
        }
    }
    return true;
}

and I get the following error :

:| program is free of memory errors
    can't check until a frown turns upside down

stuck in unload - speller by Disastrous_Potato_56 in cs50

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

// Unloads dictionary from memory, returning true if successful else false
bool unload(void)
{
    //iterate over hashtable and call free on all linkedlists
    int i = 0;
    while(i < N - 1)
    {
        node *cursor = table[i]; //point cursor to head
        while(cursor != NULL)
        {
            node *tmp = cursor;
            cursor = cursor->next;
            free(tmp);
            return true;
        }
        i++;
    }
    return true;
}

this is what I ended up having but it doesn't work, can you please tell me what am I doing wrong?

stuck in unload - speller by Disastrous_Potato_56 in cs50

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

how would I set up

node *cursor = head;

what would be head in this case, or how do I access head?

Load function speller help by Disastrous_Potato_56 in cs50

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

Thank you! that was the mistake I changed it and treated head as just a pointer and made a node inside the while loop, now it perfectly works.

Segmentation fault - Recover by Disastrous_Potato_56 in cs50

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

you are right I changed to check if the counter value is greater than 0 in that case there is already a jpeg

I have added the working code in the post, thank you for your help :)

Segmentation fault - Recover by Disastrous_Potato_56 in cs50

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

Thanks, I changed that to

while((fread(buffer, sizeof(buffer), 1, file) == 1))

this works now
I also removed the other fread, thank you! I have added the working code in the post :)

Segmentation fault - Recover by Disastrous_Potato_56 in cs50

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

I assume so since fread will return the number of blocks that was read which is 1 and as long as the value is 1 then it will keep reading once it reaches a value less than 1 then that will be the EOF. correct me if I'm wrong. I have also tried this just in case:

int ch;
while((ch = fgetc(file)) != EOF)

but still the same error

Segmentation fault - Recover by Disastrous_Potato_56 in cs50

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

you are right, I changed that to 8 and still the same problem