Sign in to follow this  

Something very wierd and confusing

This topic is 3858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well ill post abit of the code below but basical this function checks to see if two LPSTR strings are the same and if so does whats int he if statment but it dose not do that at all even thought the message boxs output says there the same so just alittle confused as to why this is not working im using VC++ express void LINKEDLIST::DeleteListNode(LPSTR WindowID) { ListNode *ListPtr, *ListPtr2; ListPtr = ListHeader; if(ListPtr->WindowID == WindowID) { ListHeader = ListPtr->Next; delete ListPtr; } ListPtr2 = ListHeader; while(ListPtr != NULL) { MessageBox(NULL,WindowID,ListPtr->WindowID,MB_OK); if(WindowID == ListPtr->WindowID) { ListPtr2->Next = ListPtr->Next; delete ListPtr; MessageBox(NULL,"Item Removed From List",NULL,MB_OK); return; } ListPtr2 = ListPtr; ListPtr = ListPtr->Next; } MessageBox(NULL,"Nothing removed from list",NULL,MB_OK); return; } so yeah any thoughts would be nice -.^

Share this post


Link to post
Share on other sites
When comparing two LPSTRs, you are comparing the pointers, not what they are pointing at. (LPSTR is a typedef for "long pointer to string"). So:

if ( listPtr->WindowID == WindowID )

...will return true if and only if the pointers are the same. That need not be the case - consider:

int a = 1;
int b = 1;
int* p1 = &a;
int* p2 = &b;
if ( p1 == p2 ) { /* will never get here */ }
if ( *p1 == *p2 ) { /* will get here */ }

Sounds like you want to check if the strings are the same, something like as follows:

if ( strcmp( listPtr->WindowID, WindowID ) == 0 )

... where strcmp is a function that compares strings, returning how different they are (so 0 is identical).

Share this post


Link to post
Share on other sites
LOL oh duh ..... way to make myself seem stupid i had a sneaky suspicion about that.

Well thanks for your time!

Share this post


Link to post
Share on other sites

This topic is 3858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this