I have a method called getNode
which takes a char str[]
looks through a Linked List (struct Node* ptr
)
After adding all elements to my linked list, I'm then saying:
This is what's inside my main Method
struct Node* X
X = getNode(str, temp)`
Here is my getNode method
struct Node* getNode(char str[], struct Node* start) {
struct Node* ptr = start;
while (ptr != NULL) {
// printf("Comparing [%s] with %s\n", str, ptr->varName);
if (!strcmp(ptr->varName, str)) {
return ptr;
}
ptr = ptr->next;
}
//printf("going to return null");
return NULL;
}
then I make a condition back inside my main method
if (X == NULL){
// will do something
}
But I'm getting a segmentation fault between these two codes, how do I fix this?