For some reason, whenever I try to find a slash at the end of a byte string (in this case, base_url which is set to "www.google.com/"), it doesn't seem to want to return that it is or isn't there. However, if I change base_url to something like "www.google.com" where m is the last character, then it finds it just fine.

//in this case, the base_url is "www.google.com/". I also tried to simply put //"www.google.com/" in place of the base_url, just in case.

char * last_char_ptr;
last_char_ptr = strrchr(base_url, '/');

if(last_char_ptr == NULL)
{
     cout << "it is null!" << endl;
}
else
{
     cout << *last_char_ptr << endl;
}

Whatsup?

It's unlikely that what you describe is happening. Consider

#include <cstring>
#include <cstdio>

const char url[] = "www.google.com/";

int main () {
    char * pos = strrchr (url, '/');
    if (pos) {
        printf ("Found / in %s\n", url);
    }
    return 0;
}

I've run that 100 times each time the '/' is found. It is most likely the case that you are not getting the input you expect.

commented: Showed some effort behind his work. +0

You are right. However, the input was correct - I simply misinterpreted the meaning of the strrchr function - I thought it only searched the last character and matched it, but instead it searches the entire cstring and matches the last OCCURRENCE of the given character, yielding a much different result. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.