Skip to main content
8 votes
Accepted

(pset5) valgrind - 1 block not freed

Hmmm..... 568 bytes in 1 block.... sounds like a file pointer. Did we forget to close an open file somewhere???? ;-) Side note: valgrind usually tells you how you can get more information, ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

Speller.c finds some words, but says that correct words are mispelled PSET 5 - Speller

One problem is here: word[strlen(word) - 1] = '\0'; You would need to "null out" the newline if using fgets. Not so with fscanf, it does not include the newline. From man fscanf: s Matches a ...
DinoCoderSaurus's user avatar
2 votes
Accepted

pset5 trie: What is the boolean-data value in the root node if the dictionary has one-letter words?

The trie starts at one root node. This node will always have the is_word bool as false because the root node doesn't actually represent a letter. For a one letter word, say a, you would first move one ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

too many misspelled words

Do not replace the value of root within check. That way, you replace your trie with an empty one. Here in Germany we sometimes call that a "Guttenbug", a bug by faulty copy&paste. (Semi-funny ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

pset5 speller Invalid write of size 1

Did you know that sizeof(word) returns the length of the word variable? That's right, 8 bytes on a 64-bit system. The variable stores a memory address of the first byte of the string (stored somewhere ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

Pset5 - Valgrind causes 9544106 errors, Uninitialised value was created by a heap allocation

The issue lies in how you are initializing your nodes. for (int i=0; i<27; i++) { trav->next[x]=NULL; } What is x on that line? Pay special attention to your counting variable in the loop. ...
curiouskiwi's user avatar
  • 18.7k
2 votes
Accepted

Finance index function does not return lookup value in index.html

Each dict in portfolio contains 3 keys as returned from the execute. There is no key current_price, so the html does not render anything for that column. If the key gets created in the for loop in ...
DinoCoderSaurus's user avatar
1 vote

Stuck on the unload() function. Possibly wrong logic used on load() and check() using tries

sizeof(word2) will give you the size of a pointer on your system, in bytes, most likely 8 for a 64 bit system. You probably meant strlen(word2). The comparison makes no sense in the initialisation ...
Blauelf's user avatar
  • 21k
1 vote

dictionary - need some hints to target details why it doesn't work - please

Unclear what this is meant to do in load How would pointer->is_word already be true? Shouldn't your load be setting it to true when you reach the end of the word? //if newline means end of word ...
curiouskiwi's user avatar
  • 18.7k
1 vote
Accepted

Pset5 Dictionary C Struct Array Call In Load Function Issue

fscanf needs some memory to write to, so char word[LENGTH + 1]; is probably the way to go. You might want to strcpy the result to a new node's word property in case of success. Please note that the ...
Blauelf's user avatar
  • 21k
1 vote

PSET 5: I've made a mistake somewhere in the load() function but can't pinpoint the problem

Looks a bit unorganised, but I cannot spot any obvious mistake. For a hashtable, you don't need any headp array. You seem to keep it at the same values as hashtable anyway. Usage of a global key ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Speller(hashtable) flagging all words as misspelled

First: You seem to have different spelling of wordcount/wordCount. Are you sure that's the code that you compiled and had valgrind on? while (fscanf(fp, "%s", buffer) != EOF) might better be while (...
Blauelf's user avatar
  • 21k
1 vote
Accepted

segfault in speller.c

In check, you never test a pointer for being NULL. In load, you don't initialise the is_word field. Also, you initialise the children array before you test whether the structure exists (or the ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Pset5 Unload Giving Double Free or Corruption error

You have a tree structure (yes, a trie, but that's more a variation), and I don't see how you intend to free all nodes. One misconception you seem to have is that freeing something makes the pointer ...
Blauelf's user avatar
  • 21k
1 vote

Pset5 dictionary.c load and check: returning all words as misspelled?

The unload function is intended to do all the freeing. When this line free(ptr); executes in the load function it is freeing the root node. Why? last line feed of last word does this ptr = root;. ...
DinoCoderSaurus's user avatar
1 vote
Accepted

Speller, works for given dictionaries but not the ones used in check50: segmentation fault

Answered over in the subreddit, but I'll repeat it here: It segfaults for me when I use the given small dictionary. I'd look at your check and unload functions. What happens if htable[i] is NULL, ...
curiouskiwi's user avatar
  • 18.7k
1 vote
Accepted

PSET5: speller - Program terminated with signal SIGKILL, Killed. The program no longer exists

I haven't seen that kind of message before, but I assume you are experiencing a "segmentation fault", accessing a memory region that your programme is not meant to access. I'd expect root to be a ...
Blauelf's user avatar
  • 21k
1 vote

Pset 5 speller trie check function - check50 handles everything but possessives and substrings

Your node should have some property telling whether it encodes a word, or is just the beginning of one, like the trav->children[c]->is_word you mentioned in the comment. I don't think it's a ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Why does this hash function fail?

I assume you have created str2 for the case insensitivity. No memory has been allocated to it, therefore anytime you write to it (as with strcpy), there will be an "invalid write". (And if you ...
DinoCoderSaurus's user avatar
1 vote
Accepted

Pset5 - Could not open dictionary

I don't think that this is a code problem, but is a file name problem. I believe the dictionary name is small, not small.txt. If this answers your question, please click on the check mark to accept. ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

PSET 5 Words not loading in memory

I'm highly suspicious of the following two lines: char* temp = NULL; while (fscanf(dict, "%s", temp) == 1) The temp var is a pointer set to NULL, which you then try to read a string into. No memory ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

PLEASE HELP How to contemplate the last line in dictionary (the empty one)

Instead of your current while loop, try while fscanf(etc...)!=EOF //malloc new node, etc.
ronga's user avatar
  • 1,415
1 vote
Accepted

PSET 5: Dictionary.c, Trie structure, Check/Load, All words misspelled

You're on the right track - there is something wrong in load(). It's a subtle logic problem. When you process each character, the following line is processed: strider = strider->children[...
Cliff B's user avatar
  • 69k
1 vote
Accepted

Cannot load dictionary

If you're getting the "cannot load dictionaries/large" error, it sounds like it isn't a coding problem, it's a file location problem. For the default dictionary to load, it has to be named large, and ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

Unknown problem with dictionary.c Help!

you are trying to compile dictionary, at this point should know that you can not compile a program that does not have main () function instead must compile speller.c, plus you have in pset5 directory ...
MARS's user avatar
  • 5,169
1 vote

PSET5 Question about pointers

Regarding const Exact reason you're putting const there is to notify 1) the compiler that you have no intentions to modify that variable. Allowing it to optimize or throw an error just in case you ...
aquablitz11's user avatar
1 vote
Accepted

Problems with hash function in pset5

The code will return index % HASHSIZE;, but where is index calculated? Maybe index was supposed to be hash? If this answers your question, please click on the check mark to accept. Let's keep up on ...
Cliff B's user avatar
  • 69k
1 vote

Kinda confused with what needs memory allocated in pset5

well, no where to start, first see the hash tablenode* hashtable[ALPHA], is an array of pointers to node, are pointers we will use to store our words according to their index hash, to equal hash index ...
MARS's user avatar
  • 5,169
1 vote
Accepted

Implementing a trie. Updated load function in dictionary.c causes more problems with valgrind

I'm trying to figure out the best way to tell you this so that you can find it on your own, without just telling you where the problems lie. The good news is that the total memory leak code fix is ...
Cliff B's user avatar
  • 69k

Only top scored, non community-wiki answers of a minimum length are eligible