Odd :scratch:
That line looks exactly the same as a previous line that isn't throwing an error. .?????
That line looks exactly the same as a previous line that isn't throwing an error. .?????
#include <stdio.h>
#include <stdlib.h>
struct node{
int value;
int count;
struct node *next;
};
int main(){
int n = 0;
int readin;
int worked;
struct node readlist;
struct node refnode;
worked = scanf("%d", &readin);
printf("checkpoint 1");
if(!worked){
fprintf(stderr, "INVALID INPUT VALUE");
return -1;
}
if(worked == EOF){
return 0;
}
readlist.count = 1;
readlist.value = readin;
readlist.next = NULL;
n = 1;
//
//
//ERRORS?!?!
//(next line)
//
worked = scanf("%d", &readin);
while(worked != EOF){
if(!worked){
fprintf(stderr, "INVALID INPUT VALUE");
return -1;
}
refnode = readlist;
printf("reading %d", readin);
int i;
int found = 1;
for (i=0; (i<n) && (refnode.value<readin); i++){
refnode = *refnode.next;
if(i<n){
found = 0;
}
}
if (found ==0){
refnode = readlist;
for(i=1; i <n ; i++){
refnode = *refnode.next;
}
struct node temp;
temp.value = readin;
temp.next = NULL;
refnode.next = &temp;
n++;
}
else if (refnode.value == readin){
refnode.count++;
}
else{
struct node temp = refnode;
refnode = readlist;
while((*refnode.next).value!=temp.value){
refnode = *refnode.next;
}
struct node temp2;
temp2.value = readin;
temp2.next = &temp;
refnode.next = &temp;
}
}
refnode = readlist;
while(refnode.next !=NULL){
printf("%d %d\n", refnode.value, refnode.count);
refnode = *refnode.next;
}
printf("%d %d\n", refnode.value, refnode.count);
return 0;
}
Program received signal SIGSEGV, Segmentation fault.
0x00000000004007ac in main () at test.c:50
50 refnode = *refnode.next;
list_node *newnode = malloc(sizeof(struct list_node));
newnode->value = somevalue;
newnode->next = listhead;
listhead = newnode;