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 ...
  • 1,389
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 ...
  • 1,412
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 ...
  • 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 ...
  • 66.7k
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 ...
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 ...
  • 17.6k
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 ...
  • 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]) { ...
  • 66.7k
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) ...
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
  • 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 ...
  • 66.7k
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 ...
  • 20.8k
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 ...
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.
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] = {}; ...
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 ...
  • 7,366
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 ...
  • 66.7k
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 ...
  • 66.7k
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 ...
  • 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 ...
  • 66.7k
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 ...
  • 7,366
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 ...
  • 66.7k
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]; ...
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]...
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); ...
  • 66.7k
2 votes
Accepted

Declaring struct node and node array globally (hashtable implementation)

A global variable is one that can be used anywhere in the program. Generally, globals are considered to be a bad practice, but there are times where they are perfectly appropriate for the situation. ...
  • 66.7k
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 ...
  • 18.5k
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 ...
  • 17.6k
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]" ...
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 ...
  • 1,415

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