+ 1
problem in my code please help
please help !!! when i call this function with correct arguments i.e those present in the linked list this works but when i call it with something that is not in list it crashes rather than returning false; bool validate(string a ,string b,string c) { node *temp = head; while(temp!=NULL) { while(temp->username!=a) { temp=temp->next; } if(temp->password!=b) { temp = temp->next; } else if(temp->type!=c) { temp = temp->next; } else { if(temp == NULL) { return false; } return true; } } }
2 odpowiedzi
0
What if the nested while loop ends up not matching temp->username with a and it continues till the node is assigned NULL, after this you'd try to access data from a NULL node,this will make your program crush.
Provide an exception mechanism in the nested while loop to check if temp==NULL,if it is return false.
0
thank you your answer really helped!