Sign in to follow this  
Pharazon

Dealing with pointers

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 )
{
    cout << "Not Found!";
}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 this post


Link to post
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 this post


Link to post
Share on other sites

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