Copy works fine until the while loop
What is the issue with my code?
hi @tusharnitharwal segmentation faults mean that you are probably trying to access a memory location which is not there. You should dry run your code and see where’s the fault.
I’ve tried many times but cant find a problem. There is some issue with the while loop. Plz help me figure it out
HI @tusharnitharwal in line 129, you have declared copy but you have not initialsed it. Meaning, it is not pointing anywhere (anywhere meaningful). Then you assign use to copy as well, which again is pointing nowhere, not to a node at least. Then you are trying to access ‘use->data’ but data is a data member of the node class and use is not pointing to an object of the node class right now. Hence there is a segmentation fault.
@tusharnitharwal i think you are a bit confused between objects of classes, and pointers to those objects. Better clear that up.
okay got it.
Thanks a lot!