I'm simply trying to find the length of the linked list, but my findSize() function isn't working right and I'm not sure where it's going wrong...I get a segmentation fault when i run it, so probably out of bounds somewhere...just where?
Code:typedef struct node { char* value; struct node* next; } LinkedList; int main() { char str1[] = {'t', 'e', 's', 't', '\0'}; LinkedList* ll = llCreate(); llAdd(&ll, str1); int* size; findSize(ll, size); printf("%d", *size); } void findSize(LinkedList* ll, int* size) { LinkedList* p = ll; while(p != NULL){ (*size)++; p = p->next; } } LinkedList* llCreate() { return NULL; } void llAdd(LinkedList** ll, char* value) { LinkedList* nn = (LinkedList*)malloc(sizeof(LinkedList)); nn->value = value; if (*ll == NULL) { *ll = nn; } else { // General case - find the end LinkedList* p = *ll; while (p->next != NULL) { p = p->next; } p->next = nn; } }



LinkBack URL
About LinkBacks




