# Dealing with pointers

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

## Recommended Posts

Alright, here is my problem, for some stupid reason I can't get this to return the current item that my 'finder' is pointing to when it finds the name in the linked list. ( I cut out other parts of it to try and limit to smaller problem, and it problems here) Code:

typedef char str[25]

typedef struct NPC {
str NAME;
str LOCATION;
NPC *next;
} NPC;

NPC *FindPos (EntryType *nps, str name)
{
NPC *cur = nps;

while ( cur )
{
if ( cur->NAME == name )
{
return cur;
}
cur = cur->next;
}
return NULL;
}

Now, I tried:
NPC *toFind = FindPos( g_NPCS, "Kain" );
if ( !toFind )
{
}else
cout << "FOUND!" << endl;
cout << toFind->LOCATION << endl;
}

Now I made sure it was added into the list, I'd display the list, it showed it was in the list, yet it never actually see's it if I look for it to display.. Anyone see a problem?

##### Share on other sites
If I had to guess this: cur->NAME == name is the problem. The == operator on character arrays doesn't perform string comparisons. You can either use strcmp() to compare strings or just use a std::string object instead of your char array.

##### Share on other sites
I see.. I kinda thought so, but didn't really know.. thanks alot mate :)

• 32
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631349
• Total Posts
2999473
×