5 votes
Accepted

PSET5 speller segmentation fault

Initially you have declared node *table[N] as global pointer. As you might have already guessed, all global variables/ pointers are set to default values.(In this case, each pointer is set to NULL). ...
C--'s user avatar
  • 306
4 votes
Accepted

Recover Segmentation Fault

Your code has several issues. First, you're hitting the seg fault because you are trying to close a nonexistent output file when you hit the first signature. Second, you're declaring img twice ( FILE ...
Cliff B's user avatar
  • 68.3k
4 votes
Accepted

Segmentation Fault on Inheritance, Lab 5

You don't actually assign to p->parents[1] // TODO: Recursively create blood type histories for parents p->parents[0] = create_family(generations - 1); p->parents[0] = create_family(...
Fuelled_By_Coffee's user avatar
3 votes
Accepted

pset2 initializing segmentation fault

isblank(_), like isupper() and islower(), takes a single character as an argument. You are passing it an entire string and it's choking on it, causing a seg fault. isblank(name[i]) solves the issue ...
Cliff B's user avatar
  • 68.3k
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

I just finished pset2 caesar. I get a segmentation fault if argc is other than 2

int k = atoi(argv[1]); if (argc != 2) {........... You are assuming that argv [1] exists before checking that really exists, if we have more than two arguments your program will work well, but if you ...
MARS's user avatar
  • 5,169
3 votes
Accepted

pset4 recover.c Segmentation fault

The root cause of your seg fault is this: char * nameoffile = ""; When you create a string in memory, the space allocated is fixed at that time. In this case, you created a string of length 0 plus ...
Cliff B's user avatar
  • 68.3k
3 votes
Accepted

Pset2 Vigenère cipher solution Segmentation fault

You did a pretty good job of narrowing the problem down! if(isupper(argv[1])) The isupper() function (and all it's cousins) takes a single char as input, but argv[1] is a string, not a single char. ...
Cliff B's user avatar
  • 68.3k
3 votes

about caesar,i'm having a segmentation fault

Segmentation fault means that you are trying to access a section of memory that you don't have permission to use. This happens when you try to access an index of an array that doesn't exist. Before ...
Larpee's user avatar
  • 196
3 votes
Accepted

Vigenere Segmentation understanding

This is a very, very common error for new programmers. The problem is the actual call to isalpha(). The isalpha() function takes a single char as input, but argv[1] is a string, not a char. Simply ...
Cliff B's user avatar
  • 68.3k
3 votes
Accepted

Pset4 Recover: Program creates segmentation fault

There are a couple of problems in the code. Ordinarily, I'd suggest that you need to identify which line is causing the seg fault, but it looks like you're stalled out on that. In this case, running ...
Cliff B's user avatar
  • 68.3k
3 votes
Accepted

pset4 filter: reflect produces "UndefinedBehaviorSanitizer:DEADLYSIGNAL" forever

for (int i = 0; i < width; i++) Shouldn't it be height?
Blauelf's user avatar
  • 20.9k
3 votes
Accepted

Pset4 Recover conceptually struggling

First, you really, really need to learn how to determine which line is generating a seg fault in any program! Seg faults are going to occur over and over and over. This is one of the most critical ...
Cliff B's user avatar
  • 68.3k
3 votes
Accepted

Plurality Pset 3 I need Help

Segfault is a memory error which is caused due to leakage in memory or aka bytes I need to see the whole code Remember you only need to print the name of the candidate(s) once it's vote matches the ...
Shehroz Ali's user avatar
3 votes
Accepted

Segmentation Fault while running caesar

The immediate problem lies here: if ( isalnum(k [1]) || argc == 2) The isalnum() function requires a single char to be passed to it. k[1] is a string. Pass a string to isalnum or any of it's ...
Cliff B's user avatar
  • 68.3k
3 votes
Accepted

pset 2 Segmentation fault (core dumped)

Look at this line of code: if (isdigit(s)) The isdigit() function takes a single character as input, but s is a string. This triggers a seg fault. The code needs to process each char in the string, ...
Cliff B's user avatar
  • 68.3k
2 votes

pset5 trie check segmentation fault

OK, after careful debugging I have discovered and fixed the issue. It doesn't have to do with malloc/calloc. Even though my forward declaration of the struct/root node was properly placed outside of ...
Avishai Fuss 's user avatar
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

pset5 Check Function (trie version) giving a segmentation error

I just figured out the answer (in case anyone has a similar issue). And actually the error was in Load so apologies for not including that (I didn't want to paste too much of the pset in). I declared ...
jamiej's user avatar
  • 21
2 votes

Segmentation fault in recover.c of pset4

FILE* img = fopen(title, "w"); // SEGMENTATION FAULT OCCURRING REALLY HERE This is because char title [3] does not have enough space to store the title, change it to char title [8] for example
MARS's user avatar
  • 5,169
2 votes
Accepted

Segmentation Fault in load function of pset5

The problem lies in your hash function. It produces a number in i that is so large that it overflows. The result is treated like a two's complement, so it's generating a negative number that is then ...
Cliff B's user avatar
  • 68.3k
2 votes
Accepted

PSET 4 recover: segfault when reading buffer

What I think is going on is: When you declare unsigned char* buffer you are creating a pointer, which has the value of an address in memory. When you pass &buffer to fread, the ampersand ...
Kathleen's user avatar
2 votes

How to copy a string in pset2? strcpy results in segfault

The main reason for the seg fault is this string titleized_string = "";. As soon as you "set" titleized_string to "something-in-quotes" it becomes a constant. You cannot strcpy into a constant (it ...
DinoCoderSaurus's user avatar
2 votes
Accepted

Why does this recursive factorial function hit segmentation fault?

The fact() function is a recursive function that takes a pointer to an int as input. However, the internal recursive call, return *a * fact(a - 1); is not passing a valid pointer to an int. It's clear ...
Cliff B's user avatar
  • 68.3k
2 votes
Accepted

Odd IDE behavior during pset4

The problem lies early in your code: if (argc != 4 || !isdigit(argv[1])) The isdigit() function is designed to check whether a single character is a digit, not a string. This code is trying to ...
Cliff B's user avatar
  • 68.3k
2 votes
Accepted

CS50 PSET5 Trie Segmentation Fault

As noted in the comments, root is not declared globally. It is declared as a local var in both load and check. By declaring it locally in load, the local var root is destroyed when load ends. That ...
Cliff B's user avatar
  • 68.3k
2 votes
Accepted

PSET5 segmentation fault cannot scan the word correctly

In your definition, typedef struct node { char* string; struct node* next; } node; string is a pointer, but space hasn't been allocated. When the code executes the strcpy, there's no ...
Cliff B's user avatar
  • 68.3k
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=='...
Blauelf's user avatar
  • 20.9k
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=...
J Doe CS50's user avatar
2 votes
Accepted

pset4 recover with malloc having a segmentation fault

char c[3]; is the guilty declaration of segfault, the array space is insufficient should be resolved with: char c[8]; keep in mind that we must store something like 001.jpg which are seven ...
MARS's user avatar
  • 5,169

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