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 ...
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 ...
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 ...
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
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 ...
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])
{
...
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
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 ...
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 ...
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 - 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 ...
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
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 ...
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);
...
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. ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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....
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
load × 419pset5 × 277
speller × 156
pset6 × 89
check × 57
trie × 42
segmentation-fault × 39
dictionary × 34
server × 30
cs50x × 22
valgrind × 22
indexes × 18
unload × 14
check50 × 12
hash-table × 12
memory-leak × 11
c × 10
speller-load × 8
gdb × 7
hash × 7
pointers × 6
parse × 6
function × 6
segfault × 6
pset4 × 5