Implementing Sieve of Eratosthenes using Linked List in C (Segmentation Fault error)-Collection of common programming errors
I’m attempting to implement the Sieve algorithm in C for a class. I’m not asking for this assignment to be done for me. I’ve got my functions written out already, but am currently getting a Segmentation Fault error. I’m not 100% sure what that is. Here is my code so far, can anyone see where this error comes from?
#define EXTERN
#include
#include
#include "header.h"
void clearAll() {
int i, j;
seg *p;
p = head;
for(i = 0; i < NSegs; i++) {
p = p -> next;
for(j = 0; j < 256; j++) {
p -> bits[j] = 0;
}
}
}
int setBit(int n) {
int segment, index, hold, pos, i;
seg *p;
p = head;
segment = n/256;
hold = n;
while(hold > 65) {
hold = hold - 65;
index++;
}
pos = (hold - 1)/2;
for(i = 0; i < segment; i++) {
p = p -> next;
p->bits[index] = p->bits[index] | (1 65) {
hold = hold - 65;
index++;
}
pos = (hold - 1)/2;
printf("%d, %d, %d ", segment, index, pos);
for(i = 0; i < segment; i++) {
p = p -> next;
r = p->bits[index] & (1