billy reynolds
billy reynolds

Reputation: 23

string comparison fails c++

I don't really know what's going on in here, but when I'm running my code I get some wild error while trying to compare two strings.

bool remove_entry(addlist& list, std::string fname, std::string lname){
    bool more = true;
    bool failed = false;
    contact* traversal_ptr = entry;
    contact* trailer = entry;

    while (more && !failed){
        if (traversal_ptr = NULL){
            failed = true;
        }
        else if (traversal_ptr->last_name != lname || traversal_ptr->first_name != fname){
            trailer = traversal_ptr;
            traversal_ptr = traversal_ptr->next;
        }
        else {
            trailer->next = traversal_ptr->next;
            delete traversal_ptr;
        }
    }
    return failed;
}

I get a failure in the return line of the following block of xstring:

    int compare(const _Myt& _Right) const _NOEXCEPT
    {   // compare [0, _Mysize) with _Right
    return (compare(0, this->_Mysize, _Right._Myptr(), _Right.size()));
    }

I don't know why this is happening. I know everything being put in is a string. It doesn't even raise an exception, so I'm not sure what to do. It seems like it might be some little thing I'm missing. Any help would be greatly appreciated.

Upvotes: 2

Views: 611

Answers (1)

sehe
sehe

Reputation: 393674

    if (traversal_ptr = NULL){

Should be

    if (traversal_ptr == nullptr){

Also, as you noted in your comment, you needed to add more = false to the else block, to terminate the loop.

Upvotes: 3

Related Questions