Questions tagged [pset5]

The problem set for Week 5 will challenge you to apply what you've learned about pointers, memory management, file i/o and structs, creating more complex data structures (such as Hash Tables or Tries) and leveraging their power to write a lightning-fast spell check algorithm.

253 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
0
votes
1answer
44 views

PSET 5 My hash table doesn't seem to be storing correctly

When I load the dictionary, I add the words to the hash table, by calling the hash function to calculate the bucket ID, then add hash function to actually insert it into the list. Inside the addhash ...
0
votes
1answer
140 views

PSET 5 Speller Failing free memory of errors final check

So i am so close to finally completing this present and i still have some final errors to go through. Valgrind is saying that it is still leaking memory for some reason and i cant find the reason why. ...
0
votes
0answers
17 views

One block still reachable plus other advice

I am trying to do pset5 speller and am running into a lot of problems Can't figure out what the problem is here. https://pastebin.com/fBkFeDA9 Also saw that the hash function is giving out negative ...
0
votes
2answers
60 views

strcpy not working with struct items

bool load(const char *dictionary) { char splitStrings[9999][45]; FILE* dict = fopen(dictionary, "r"); node* item = table[0]; int i = 0; for (i = 0; fscanf(dict, "%...
0
votes
1answer
58 views

PSET5 speller memory leak and dictionary not unloaded

I have been looking at this for about 5 days now and I can´t find where I am leaking memory or if I have any problems with my code logic. Everything compiles and Valgrind output is below. I am ...
0
votes
0answers
21 views

Help me with Pset5 filter

// Implements a dictionary's functionality include include "dictionary.h" include include include include define HASHTABLE_SIZE 1000 // Represents a node in a hash table typedef struct ...
0
votes
0answers
34 views

Help me with Pset 5 Speller

Help me Guys Where did i go wrong in my code // Implements a dictionary's functionality include include "dictionary.h" include include include include define HASHTABLE_SIZE 1000 // ...
0
votes
0answers
62 views

check50 keeps printing “Could not load basic/dict.” what might be the problem in the code?

// Implements a dictionary's functionality include include include include "dictionary.h" include include include // Number of buckets in hash table define N 120000 //maximum length of ...
0
votes
2answers
56 views

Valgrind errors: “invalid read of size 8” and “…uninitialised value” (pset5, speller)

I have basically finished the code, no memory leaking and tests work out fine. However, Valgrind is not happy: Conditional jump or move depends on uninitialised value(s): line 141 This is one of the ...
0
votes
2answers
38 views

Linked list, List isn't passing by reference?

I've really been struggling with PSET5 so I decided to take a step back and write a simple linked list program. My program take in an array of characters as a command line argument and stores each ...
0
votes
1answer
268 views

Need help: pset5 “Speller”

I am having a strange issue with the pset5. When I debug the file, it works fine, but when I check it through Check50, it throws several frowns at me. Need suggestions. Here is my code: #include <...
0
votes
1answer
59 views

almost there, but Valgrind reports an uninitialised value

Thanks in advance for helping out an old Dutchie! I am almost there, but valgrind insists i have an uninitialised value on in the While loop: while (cursor != NULL) VALGRIND tells me ==...
0
votes
0answers
94 views

Shows double free or corruption (fasttop)

// Implements a dictionary's functionality #include <stdbool.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include "dictionary.h" // Represents a node in a ...
0
votes
1answer
29 views

Speller Works on all .txt files, but FAILS Check50

My Speller function works on all the .txt files provided with the keys. I even made a .txt containing the large dictionary and all the words are spelled correctly. However, when I go to use Check50 ...
0
votes
1answer
117 views

Valgrind uninitialized values pset5

This is my solution for pset5's speller problem, which uploads a dictionary with a hash table and checks an inputed text to find misspelled words. My code works fine when I run, but valgrind says "...
0
votes
0answers
22 views

what can be rong with my check function? it returning handles substrings properly after checking

bool check(const char *word) { // TODO int exist = 0; int index = hash(word); for(node *temp = table[index]; temp != NULL; temp = temp->next) { if((strcasecmp(temp->word, word) == ...
0
votes
1answer
71 views

Check function Segmentation

I am struggling to find the problem in my check function. I have a segmentation fault that it's position varies every time I alter my code a bit. bool check(const char *word) { int index = hash(...
0
votes
0answers
41 views

Cant figure out where im going wrong with unload and check

My check function, when unload had a bunch of leaked memory returned every word as incorrect. However, now I tried to fix my memory leak and im getting a double free error upon trying to run the ...
0
votes
1answer
84 views

Getting a segmentation fault when i try to run pset5 speller and i'm not sure what's the problem. Appreciate it if someone can explain. thanks!

// Implements a dictionary's functionality include include "dictionary.h" include include include include // Represents a node in a hash table typedef struct node { char word[LENGTH + ...
0
votes
0answers
224 views

Pset5 : Speller

I'm wondering how I can solve pset5: Speller. I've been stuck on speller for about a week now. I've been looking for help, but they seem to be all using tries, and i'm using a hash table. Should I ...
0
votes
0answers
16 views

PSET 5: Speller segmantation fault

Hi everyone! I am currently trying to finish pset5, but I keep getting seg faults with speller. I am a begginer in programming, so I hope that I will be able to finish it soon! Thanks for your time ...
0
votes
0answers
31 views

Segmentation Fault in pset 5 load function (maybe)

I have looked at this for hours. I am pretty sure the segmentation fault that I get when I try to run it is from line 82 to line 97. I only think this because load never successfully prints the ...
0
votes
0answers
78 views

HI. I'm on pset5 speller mostly done but having valgrid problem. Don't understand why im geting it..Well i do understand what it says

[![enter image description here][2]][2] [2]: https://i.stack.imgur.com/yS0vD.png// Implements a dictionary's functionality include include include include include include include ...
0
votes
0answers
66 views

pset5 speller - struggling to free memory (valgrind error)

My code: #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <ctype.h> #include <cs50.h> #include "...
0
votes
2answers
5k views

PSET5 Speller hash function

I have been working on the speller problem in pset5 for a while now, and I am not able to figure out the problem in my hash function: unsigned int hash(const char* word) { int M = 1000000001; ...
0
votes
1answer
46 views

Speller - Program has memory errors, but Valgrind claims all heap blocks were freed

:( program is free of memory errors | pset5 Speller I have invalid reads at lines 148 and 153 of my code (commented out below): bool unload(void) { // CS50 for (int i = 0; i < 26; i++)...
0
votes
0answers
39 views

pset5 speller issue

#include <stdbool.h> #include <stdlib.h> #include <stdio.h> #include "dictionary.h" #include "string.h" #include <cs50.h> #include <strings.h> typedef struct node { ...
0
votes
0answers
96 views

pset5 speller seems to be working but fails in check50 - here is my dictionary.c code. Could not figured out the problem :(

//Libs include include include include "dictionary.h" include include include int dwc; // Represents a node in a hash table typedef struct node { char word[LENGTH + 1]; struct ...
0
votes
1answer
50 views

Speller: valgrind giving me segmentation fault but I can't see what's wrong with my code

I implemented speller and valgrind gives me a segmentation fault, but I just can't find the bug in my code. Please help :( Thanks a lot in advance. #include <stdbool.h> #include <stdlib.h>...
0
votes
0answers
18 views

pset5 speller fails substring test

I've run my code through check50 and it passed all the test except the substring test. Does anybody know what might be wrong with this code? // Implements a dictionary's functionality #include <...
0
votes
1answer
59 views

PSET 5 Speller Compiles, But Completely Wrong Output

I spent the last few hours trying to come up with a solution and trawled through questions on this forum but I still can't figure out why my check function is not working out properly. For some reason ...
0
votes
0answers
50 views

pset5 speller memory leak problem

This is my first post here, so if I'm doing something wrong that I'm unaware of, please correct me. Here's the thing. I've just finished my code for pset5 speller. After some tweaks and bug ...
0
votes
0answers
83 views

PSET5 Valgrind Problem!

I have my code semi working (it passes most of the check50) except Valgrind keeps reporting 'Invalid read of size 1' . Here is a screenshot of the error message: . I used the djb2 hash function. ...
0
votes
1answer
37 views

I am having a segmentation fault before my main code runs, but code will compile. pset 5 - speller

// Implements a dictionary's functionality #include "dictionary.h" // Represents a node in a hash table typedef struct node { char word[LENGTH + 1]; struct node *next; } node; // Number of ...
0
votes
0answers
30 views

Pset5 Speller: Testing Produces Different Results Between Check50 and Keys

I am getting different results when using check50 versus using diff -y [output.txt] keys/[text] to test my code. The difference is always in WORDS IN DICTIONARY and mine is always off by exactly +1 ...
0
votes
0answers
136 views

Pset 5 - Error with freeing up memory - Use of uninitialised value of size 8

I am working on Pset5 and the only issue I am having is regarding the requirement for freeing up memory. Based on the output received from Valgrind, it looks like there is no issue with the memory ...
0
votes
0answers
20 views

Pset5 - Segmentation fault (Load function) - Using a for loop to make all elements of table[i] = NULL

The following is my load function and I am having a segmentation fault when I run the executable code by typing for example when I type ./speller texts/aca.txt When I run debug50, it is pointing to ...
0
votes
0answers
40 views

Need help fixing memory leaks

I need help fixing the memory leaks on the code! I have already tried fixing them, but I have no clue how to do so. Here is the complete code: // Implements a dictionary's functionality #include &...
0
votes
2answers
23 views

freeing temporary node in functions

how to free the temporary pointer, one creates during the check function? valgrind shows error on that particular statement tried freeing it only when it has reached null, i.e., transverse over all ...
0
votes
1answer
29 views

Pset5 load problem: Dictionary cannot be loaded

I run my code and it cannot load the dictionary. I'm not sure if the problem is with my code or the file location. Anybody knows why? Thanks in advance.
0
votes
0answers
60 views

PSET 5 (speller): I don't know why I receive an inaccurate count for words in dictionary

unsigned int size(void) { int count = 0; for (int i = 0; i < N; i++) { for(node *temp = table[i]; temp != NULL; temp = temp->next) { count++; } } ...
0
votes
1answer
61 views

Pset5 Load function memory leak

Valgrind tells me I have a leak with malloc'ed node below. However, when I try to free it (free(n);) at the bottom of my code, outside the while loop, the program won't run (it doesn't pass check50 ...
0
votes
0answers
38 views

Pset5 Speller HELP!: Code looks fine but segmentation fault. Also, when should I malloc and when should I point to NULL?

I can't find what is the problem(s), been at it for days, please help! thank you! // Implements a dictionary's functionality #include <stdbool.h> #include <stdio.h> #...
0
votes
0answers
39 views

PSET 5 - Valgrind - Invalid read of 8 - Unload

So close to submission! - However, when I check using valgrind the ouptut is: ==22743== Invalid read of size 8 ==22743== at 0x40135C: unload (dictionary.c:123) ==22743== by 0x400E59: main (...
0
votes
0answers
37 views

Help on Pset5 Speller

bool load(const char *dictionary) { // Open dictionary FILE *dict = fopen(dictionary, "r"); if (dict == NULL) { printf("Could not read.\n"); return false; } ...
0
votes
0answers
59 views

Pset5 speller: segmentation fault

My code compiles correctly but when I load a text, there's a segmentation fault error. I tried to isolate the problem by commenting out certain code and the problem seems to be at this part. Would ...
0
votes
0answers
80 views

pset5 segmentation fault load() function

I'm getting a segmentation fault when I run speller. The valgrind output is as follows. I think it's due to the load() function. Valgrind output: ==8612== Copyright (C) 2002-2017, and GNU GPL'd, by ...
0
votes
1answer
93 views

pset5 - almost all words misspelled

I'm having trouble with the implementation of the PSET5 spell check code. I've looked through a lot of CS50 Stack Exchange posts, but haven't found any help. The problem is either in the check or in ...
0
votes
1answer
78 views

pset5- speller: first word and any word above 7 characters is not recognized

The 'speller' program considers any word with more than 7 characters as misspelled, even though that word is there in the dictionary. Same treatment is given to any word which comes first in the file, ...
0
votes
1answer
71 views

(PSET 5) Test for case-insensitivity fails

I used strcasecmp for comparing the words case-insensitively. However, check50 showed that I failed the test for case-insensitivity. I believe that my programme treated foO, fOo, Foo, fOO, FoO, FOo ...