Jump to content
  • Advertisement
Sign in to follow this  
Pharazon

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.

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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!