Ok, skip all the file crap for the moment:That'll put the new n's address in p back in main.Code:type *p = NULL; ... foo( &p ); ... void foo( type **p ) { if( p ) { type *n = malloc( sizeof *n ); ... *p = n; } }
Quzah.
Hope is the first step on the road to disappointment.
Thank you. That's seems to have worked in so far as the program no longer segfaults when it's in that function. It now segfaults in another function.
Nearest I can figure, is that there is something wrong with how I am coding the list traversal:
I realize that no-one here is at my beck-and-call, but I would appreciate an explanation or, at least, a link to an explanation of what I am doing wrong. I really am here to learn what I am doing wrong so I can avoid it in the future.Code:bool srchList (struct node** ptPtLnkList, int target) { bool found; struct node* ptCur; found = false; ptCur = *ptPtLnkList; if (*ptPtLnkList == NULL) { printf("Error: list is empty"); exit(201); } while (found == false && ptCur -> listEl != target && ptCur != NULL) { printf("Target not found yet 1\n"); ptCur = ptCur -> link; printf("Target not found yet 2\n"); } if (ptCur -> listEl == target) { printf("Assigning true to found"); found = true; } return found; }
If all you are doing is searching a list, and you don't need a pointer to a pointer. If you aren't changing the list, just pass the head of the list to it.Pretty much just that. Heck, you don't even need to wast time with a variable 'node', you can just use the 'list' ptr. If you DO want to pass a ptrtoptr:Code:type seekit( type *list, type tofind ) { type *node = NULL; if( list ) { for( node = list; node; node = node->next ) { if( node->data == tofind ) { ...yay... } } } return bad; }That instead. Then just use node as per normal.Code:type *node = *list;
Quzah.
Hope is the first step on the road to disappointment.