Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ String Compare

Name: Anonymous 2011-09-21 16:58

Sup niggaz. This shit is throwing an exception when it gets to this code in runtime. Any ideas?

- Assume "in" is a string comprised of "http://google.com/derp"
- found is a link found, can be w/e string

As far as I can tell, it explodes on the line where I'm trying to compare the 2 strings, as for some reason the loop is not concatenating the compare string - any idea why that is?


bool isLinkExternal(string in, string found)
{
    string compare = "";
    bool isExternal = false;

    //Get domain of original link
    for (int i = 6; in[i] != '/' ; i++)
    {
        compare += in[i];
    }
   
    //Compare domains of original and found links
    if (found.compare(7,compare.length(),compare) == 0)
        isExternal = true;

    return isExternal;
}


The way I see it, the loop starts at 7 chars in, which excludes the initial "http://". It should then keep going, concatenating each char into the compare string until a slash is found. The last bit is to compare that string to the portion of the string "in" of the same length, starting at the same point (7 chars in, for length of compare)

Name: Anonymous 2011-09-21 18:21

SOMETHING about mutable string objects or some shit like that. Who the fuck knows. C++ / java are faggot languages that CREATE problems.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List