Hot answers tagged

7 votes
Accepted

Try to use trie in pset5

You can do it. It's a good practice to initialize the values to something, NULL in this case, to prevent any garbage value remaining in the memory from messing with the execution of the code. I don't ...
user avatar
  • 1,359
5 votes

How to start with load function in server.c?

When I hit my road block here, I went back to the source code and re-watched the walkthrough videos, specifically this one: https://www.youtube.com/watch?v=OnAItxJhS70 There are subtle hints ...
user avatar
  • 1,424
4 votes

Help with .php files in Pset6 -> Load

You want function load() to work for both: files that have been opened by fopen() pipes that have been opened by popen() I also did not manage to make it work by using fseek I solved the problem ...
user avatar
  • 141
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 ...
user avatar
  • 63.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 ...
user avatar
3 votes

Try to use trie in pset5

should I let the array point to NULL when I define the struct in the beginning? If your struct definition looks like this struct node { struct node *arr[27]; }; then you actually can't assign ...
user avatar
  • 17.3k
3 votes
Accepted

Completely stuck on LOAD in pset5 (hash-table)

While I may or may not agree with the previous comment, none of those things will cause any issues. Your problem is here: else { node *tmp_node = malloc(sizeof(node)); tmp_node ...
user avatar
  • 1,677
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]) { ...
user avatar
  • 63.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) ...
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
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 ...
user avatar
  • 63.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 ...
user avatar
  • 20.7k
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 ...
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.
user avatar
2 votes
Accepted

Return value of load()

The hash table that you've loaded the words into should be globally accessible since many functions will use it and a direct access would make things way easier. Also, you're not supposed to alter ...
user avatar
  • 17.3k
2 votes
Accepted

Could not load dictionary in cs50 pset6

Try removing the semicolon after your if statement. if(d == NULL) { printf("Could not load %s\n",dictionary); return false; }
user avatar
  • 1,317
2 votes

Pseudocode for Load Function in PSet6

For steps 2-3, the data structure (e.g., the hash table in your case) that's gonna be used to store the words in the dictionary and the array of pointers to variables of that type both should be ...
user avatar
  • 17.3k
2 votes
Accepted

Improve load time in pset6

Should I try to improve it more? Yes, if you wish! Does it matter? It's meant to challenge the staff and yourself at the first place, so officially it doesn't matter. If I should improve more ...
user avatar
  • 17.3k
2 votes
Accepted

How can I avoid segfaults when sorting my linked list?

Regardless of whether the code does what it should do or not, the problem is likely to be caused by the fact that you are trying to access cursor->next when cursor is actually a null-pointer. This ...
user avatar
  • 17.3k
2 votes
Accepted

pset5 why only strcpy works

This is the way strings work in C. Because a string in C is an array of chars, you can only initialize it during the declaration. If you want to change its contents after the initialization, or if you ...
user avatar
  • 71
2 votes
Accepted

Trie Spellchecker unload() - two allocs not freeing

You overlooked something. Here's a hint. What is the integer value of ' - 'a'? Or, subtract the ASCII value of 'a' from the value of an apostrophe? I'm actually surprised that your code isn't ...
user avatar
  • 63.1k
2 votes
Accepted

Pset5: problem with inserting words into nodes

I think the problem might be here: char* word[LENGTH + 1] = {}; If you use the star and the brackets, you are declaring an array of pointers to chars. Try instead just char word[LENGTH +1] = {}; ...
user avatar
2 votes
Accepted

Inserting word into hash array, and linked lists

I will give you the pseudocode and let you convert it to actual code yourself. if hashtable[hash] is NULL make hashtable[hash] point to new_node else create a temporary_node make ...
user avatar
  • 7,326
2 votes
Accepted

Problem Set 5: Speller, Segmentation fault

Your error originates a lot earlier in the code. Look at the first two lines in your do loop: a = fgetc(file); int hash_value = hash(word); Your first problem is that you only read a single ...
user avatar
  • 63.1k
2 votes
Accepted

Initializing multiple variables inside a for loop

Why not just create an array of pointers to nodes? struct node* foo[27]; Then you can use a loop to assign NULL to each element by indexing through the array. If this answers your question, please ...
user avatar
  • 63.1k
2 votes

Cannot clear segmentation fault in load pset5

There is one mistake here: while (fgetc(ptr) != EOF) doesn't just work as a condition, but it does read a char and moves on, so next time you read a string it's gonna miss the first char of the word ...
user avatar
  • 7,326
2 votes
Accepted

pset5 - possessives and substrings

Actually, your problem is a lot more severe than it appears. You are getting a massive number of false positives. I say that they're false because you're not actually checking the words correctly. So ...
user avatar
  • 63.1k
2 votes
Accepted

Problems with letters "a" and "I" misspellings

TL; DR: This looks like a memory leak. Remove: node *tableindex = malloc(sizeof(node)); tableindex = hashtable[ind]; ... free(tableindex); Add: node *tableindex = hashtable[ind]; ...
user avatar
2 votes
Accepted

The load function in dictionary.c is segfaulting. 3 tfs have looked over my code and none can figure out what's going on. Can anyone help?

TL; DR: Change if (fscanf(input, "%45s", new_node -> word) != EOF) to if (fscanf(input, "%45s", new_node -> word) == EOF) and new_node -> next = hashtable[n] -> next; hashtable[n]...
user avatar
2 votes
Accepted

PSET 5, Load function, Segmentation Faults

The problem is that you're trying to assign content to vars that don't exist. Look at the following: if (hashtable[index] == NULL) { strcpy(hashtable[index] -> word , buffer); ...
user avatar
  • 63.1k

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