Skip to main content
4 votes
Accepted

pset 5 The dictionary pointer, why is it a char*?

The parameter being passed in is not a file pointer, it's the name of the file, a text string. That name is used inside of load() to open the file pointer locally. A pointer could be passed, but ...
Cliff B's user avatar
  • 69.1k
4 votes
Accepted

Pset6 load returns length zero for php files

You would need to use debug50 or gdb to "stop the program and inspect", not check50. Since you are asking for help with debugging, my comments are intentionally cryptic. If load returns false, you ...
DinoCoderSaurus's user avatar
3 votes
Accepted

Segmentation fault - load() function

The seg fault happens because the code is trying to make an assignment to something that doesn't exist. Look at the following code block: if(!root[index]) { ...
Cliff B's user avatar
  • 69.1k
3 votes
Accepted

Pset6 problem in indexes and load function

Here are specific things to look at: load Declare c as an int instead of size_t, since size_t is unsigned. indexes Your allocation for path2 is wrong char* path2 = (char*)malloc(sizeof(strlen(php) ...
DinoCoderSaurus's user avatar
3 votes
Accepted

Problem with edX pset 5 - Spellchecker load - segfaults with large dictionary

For this line: letterIndex = c - '\''; try to see what happens if c == 'a', the ASCII code for '\'' is 39. Try fixing this and see what happens
Chris Shi's user avatar
  • 120
3 votes
Accepted

PSET5 Speller, faster check and load times hashmap

This is an ineffective use of a hash function. In essence, your load function simply inserts each word sequentially into an array, along with a hash number, and the check function is doing a linear ...
Cliff B's user avatar
  • 69.1k
3 votes
Accepted

pset5:(speller) Check function does not correctly identify misspelled words

check: tolower(word[i]) returns the lowercased ith character in word. You never use the value, you might want to assign it. Or remove this loop and later use tolower(word[i]) instead of word[i] when ...
Blauelf's user avatar
  • 21k
3 votes
Accepted

Could not load dictionaries/large

At a quick scan, this FILE *fp = fopen("dictionary", "r"); looks like a problem. By enclosing dictionary in quotes, it becomes a string literal. The program will look for a file ...
DinoCoderSaurus's user avatar
3 votes
Accepted

PSET5 Speller Load function skips the words from the dictionary

This while (fscanf(input, "%s", buffer) != EOF) executes an fscanf, followed immediately by this fscanf (input, "%s", buffer);, therefore it is processing every other word.
DinoCoderSaurus's user avatar
2 votes
Accepted

All words are misspelled even with the dictionary is loaded. Help?

In your load, when your hashtable[key]->next isn't null, you do this: new_word->next=head; head = new_word; what is head at this point? Last time you set it, it was for the first node ...
curiouskiwi's user avatar
  • 18.7k
2 votes
Accepted

In pset6 server.c, does using realloc() reset the file pointer for fread()?

per fread's man page: size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); The function fread() reads nmemb elements of data, each size bytes long, from the stream pointed to by ...
kzidane's user avatar
  • 17.7k
2 votes

Load function correct?

The biggest problem is that you need to null terminate *content before returning the function. I think it would be better to do this with buffer so you maintain your "*content = &buffer[0]" ...
Brendan Rafferty's user avatar
2 votes
Accepted

Pset5 load, accessing head node in linked list

There are two approaches to this. If you want to add the new node to the end of the list, you need to walk the list to the end. Create a while loop that looks for the last element in the list. In ...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

Load and Check error in pset5

Simply put, the while loop in check() never starts. Look at the following code: unsigned int c =0; unsigned int i = 0; while(c != '\0') int 0 is the same as \0 in their binary ...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

Segmentation fault in check() function

As far as your check function is concerned, here is where you can make some improvements: Instead of for(int i=0;word[i]!='\0';i++) why not for (int i=0; i<strlen(word); i++) After ...
ronga's user avatar
  • 1,415
2 votes
Accepted

Pset5: Not able to free allocated heap space in dictionary.c load function

Simply put, new_node should not be freed in load(). Think about what is happening. With each pass through the while loop, a new node is created, a word is read from the dictionary file and copied ...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

Pset5: trie check outputs 18000 out of 19000 words in austin powers

You have a very narrow but very deep trie. Each word is supposed to start at the base of the trie. Where does the second word start loading in the trie? The third? After that? ;-) If this answers ...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

Extra word in the dictionary pset5

"Ready, Fire, Aim!" Classic error. The logic of your code is this: read a line (word) from the dictionary, then process it, and then check for EOF. The problem with this is that the EOF isn't ...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

Server.c, errors in Check50, probably a problem with load function

The backtrace result from check50 indicates a memory violation/ seg fault. What happens if you make a browser request tocat.jpg? Odds are server crashes. load (assuming cat.jpg) After the first ...
DinoCoderSaurus's user avatar
2 votes
Accepted

(PSET6) hello.php always displays hello, hello, world regardless of input?

The "weird" results you report For some reason, if I alter the order in which the file extensions are searched, cat.html suddenly doesn't load. is the "unpredictable results" that happen when ...
DinoCoderSaurus's user avatar
2 votes

error in load and indexes function

Reread the specification for indexes in the instructions. Complete the implementation of indexes in such a way that the function, given a /path/to/a/directory, returns /path/to/a/directory/index....
DinoCoderSaurus's user avatar
2 votes

PSET5 Speller, faster check and load times hashmap

As usual, Cliff B has explained things very well in his answer. I'd just like to add a more succinct explanation. Your problem is that you want to keep the dictionary sorted alphabetically and also ...
hotwebmatter's user avatar
  • 3,050
2 votes
Accepted

Pset 6 - load - Help!

Definitely the right track. This While (!feof) is fraught. Remember the warnings from Week 4 > Shorts > File I/O starting around 7:30. So somehow "wrap" your while around the fread. Instead of ...
DinoCoderSaurus's user avatar
2 votes
Accepted

CS50 PSET5 Won't Work With Apostrophes

You have: else if (l == '\'' && trav->children[26] == NULL) { trav->children[26] = calloc(1, sizeof(node)); } So, what if you do have an apostrophe but trav->children[26] is not ...
Ricardo David Antonetti's user avatar
2 votes
Accepted

PSET6 Load - How To Approach? Also, Is It Better To Use While() Loop or For() Loop?

Q1. Should I use fgetc() or fread() A1.: You can make both work! Choose the one you're more comfortable with. Q2. I don't know whether to use a for loop or a while loop. Is one better for this ...
Yuri Laguardia's user avatar
2 votes
Accepted

How can I optimize load in pset5

You insert at the end of the linked list. Insertion is faster at the beginning. Instead of nodeNew->next = NULL; current = &hashTable[index]; /* iterate over nodes until reached ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

PSET5 speller (load) - fscanf function error

Do not use string word = NULL. fscanf will not "put" anything in it because NULL is a defined constant, and it will not give an error. You could end up in an infinite loop (it also will not detect EOF)...
DinoCoderSaurus's user avatar
2 votes

Pset5 - Speller - Load (loading only 1 word in dictionary)

It seems to me that because your hash function is not case-insensitive all of the words with capital letters get hashed to a different location (h) before you get to use strcasecmp.
AnneB's user avatar
  • 314
2 votes
Accepted

Problem accessing the last element of the array

If an array contains 27 elements and the first element is index 0, then the last element is index 26. The last index is always one less than the number of elements, because indexes start at 0.
DinoCoderSaurus's user avatar
2 votes
Accepted

stuck on speller Load function

No, hashtable and head are not the same thing. hashtable[] is an array of pointers that point to the beginning of a linked list corresponding to each possible hash value. Initially, every element in ...
Cliff B's user avatar
  • 69.1k

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