19 votes

Is something wrong with getType(object)?

The function detectCollision() returns NULL if there's no collision happened. You have to check whether your object is equal to NULL before you pass it to getType().
user avatar
  • 17.4k
6 votes

Speller Unload Trie with Recursion

Should I declare freenodes in the header file? It is not necessary to declare freenodes in the header file. However because freenodes is written after the function which calls it, it should be ...
user avatar
  • 2,625
3 votes
Accepted

Why do I get a segmentation fault when writing to a string?

See the C FAQ, Question 1.32 Q: What is the difference between these initializations? char a[] = "string literal"; char *p = "string literal"; My program crashes if I try to assign a new ...
user avatar
  • 483
3 votes
Accepted

GetString() giving me a segfault in C

The description of the GetString() function clearly states that it can return NULL on an error or an EOF. If you pass the return value to strlen() without checking, your program will crash. string s ...
user avatar
  • 483
2 votes
Accepted

PSET5 Speller / Dictionary - Seg Fault and Incorrect Check

You can jump to SUGGESTION for quick answer. I plugged your check() function on my dictionary.c program. I also have a trie in my dictionary.c. I don't know what is causing the segmentation fault. ...
user avatar
2 votes

Cant create linked list node

This is a really tricky mistake happened around line 50-53. A live test of your code is available here: segfault fixed, I made a fix at line 52-53 and commented out the faulty code. It works ...
user avatar
  • 450
2 votes

Do YOU know how to find a seg fault?? Advice to new programmers

Reread the post again, he explains why the seg fault happens. A quick google should suffice too.
user avatar
  • 23
2 votes

Crack: Segfault on CS50 appliance/ IDE/ CS50.io but fine on my computer

Ok, I've found answer to c segmentation fault on tail recursion: changing clang option -o from 0 to 3 fixes this problem as this enables better optimization: clang -fsanitize=integer -fsanitize=...
user avatar
2 votes

Crack: Segfault on CS50 appliance/ IDE/ CS50.io but fine on my computer

if(!offset) offset = 0; does nothing. 0 is the value of false, while anything different could be interpreted as true in many contexts (even if it does not equal true, which is 1). With word[offset=='...
user avatar
  • 20.7k
1 vote
Accepted

PSET6 Load - Check50 Server2 Errors

The program reads one byte at a time and essentially appends it to buffer. So the number of bytes that buffer needs to hold increases each read. This buffer = realloc(buffer, sizeof(char)); allocates ...
user avatar
1 vote
Accepted

Word array sometimes filled with weird values - Speller

The random values you see in word is the result of previous iterations of the loop assigning longer words than the current one. It's not an issue per se since the functions handling it (such as strlen ...
user avatar
  • 940
1 vote
Accepted

Trying to fix a segfault in unload , pset5, speller

For starters, you can't free table[i] and two lines later try to access table[i]->next. It no longer exists. That's where the seg fault comes from. This unload code is needlessly complicated. I ...
user avatar
  • 64.2k
1 vote
Accepted

PSET 5 Unload Segmentation Fault

Two problems. First, table[] was never initialized. Second, the if statement in unload allows i to be 27, which means that table[27] is selected, but doesn't exist. There may be other issues, but ...
user avatar
  • 64.2k
1 vote

Pset5 Seg fault speller

There was a little bit of code missing, so I can't tell exactly why you're getting the seg fault for sure, but I'm 99% certain of the problem. The code is treating word_count as a pointer. Why? ...
user avatar
  • 64.2k
1 vote

CS50 PSET4 RECOVER.C SEGMENTATION FAULT PLEASE HELP!

Having a look at your code was really helpful, I was having a hard time with this problem because I cant fully understand how fread works. You keep reading rawPtr and sending it to buffer, and the ...
user avatar
1 vote

Do YOU know how to find a seg fault?? Advice to new programmers

I found this post after I had asked about my segfault, and still appreciate the post. Luckily I had already debugged and found where the segfault is coming from. The problem I have now is that I don't ...
user avatar
  • 11
1 vote

Do YOU know how to find a seg fault?? Advice to new programmers

A better way to identify the source of segmentation faults is to compile with -g -fsanitize=undefined -fsanitize=address running the program should then point you to the exact line where the ...
user avatar
1 vote

Pset 5 Speller Segmentation Fault

Your code is very nice and neat congratulations. Your problem resides in your hash function. When passed a string of less than 3 caracters returns a negative value, so when you try to use it as index ...
user avatar
  • 1,561
1 vote
Accepted

Pset5 Trie Segmentation fault

It could be because you're looking in the wrong place. The code is seg faulting in the unload() function. Specifically, it fails at this line: child[i] = curr->children[i]; The seg fault ...
user avatar
  • 64.2k
1 vote

Cant create linked list node

The first thing I noticed is that the hashtable array is not allocated here hashtable[i] = NULL;. Remember, each index can hold a node. I fixed that in my repro case, but the error persisted. I ...
user avatar
1 vote

Segfault error in initials program

while(isspace(name[length - i]) && w == true) { ++i; } This loop is the culprit. when i increases, and length - i decreases. At some iterations length-i will become a negative value, and ...
user avatar
  • 450
1 vote
Accepted

Pset5: load hashtable - constantly giving seg fault

You forget to fclose the dictionary, but else... l_node->next = NULL; would be a bad idea before testing if l_node == NULL. Make sure your buffer variable and word property both can handle a word ...
user avatar
  • 20.7k
1 vote
Accepted

No errors while loading small dict, but segfault when loading large one. Pset5 Speller

Apostrophe problem. Apostrophe is 39 in ascii. (96 is backwards apostrophe, or back-tick). When check encounters apostrophe here if (word[c]<91) translated=word[c]-65; translated is a negative ...
user avatar
1 vote

GetString() giving me a segfault in C

Two things. One. Not sure why you say "not in the CS50 library" when you then pasted in the exact function that is in the CS50 library. Two. You'd generally get a segfault with strlen if the string ...
user avatar
  • 18.4k
1 vote

Pset4, Recover, GDB on fread gives an "Coud not open file" error and segfault

The problem was fileName array, it needs to be 8, not 7. sprintf was overwriting important memory because of that.
user avatar
  • 11
1 vote

pset5 Segmentation fault

You were on the right track. buckets is declared as an array of pointers, but they're not initialized, so they contain garbage data. They do need to be initialized. Next, the compiler is choking ...
user avatar
  • 64.2k
1 vote
Accepted

pset6 server giving segfault

Remember that you can't change the length of a string array once it has been created in c. Now look at the following: char requestTarget[] = ""; char query[] = ""; This code creates a couple ...
user avatar
  • 64.2k
1 vote

pset5 speller.c with hashtable errors and seg fault

use tools like gdb and valgrind to detect the cause of the problem and solve it! your load function: also do you think relying on feof may cause you to allocate more memory than you need? are you ...
user avatar
  • 17.4k
1 vote
Accepted

Vigenere code has Segmentation error

Your segmentation fault is due to the following line: if(isalpha(argv[1]))//checks if key is letters isalpha() tests to see if a single character is an alpha. It does not operate on whole strings. ...
user avatar
  • 64.2k
1 vote
Accepted

How to iterate through an array using pointers

Yes you are correct. The compiler knows what data type you are using and traverses by the correct amount of bytes every time. You just tell it how many places away from zero you want (by the + i). You ...
user avatar
  • 7,326

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