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

C++ String Compare

Name: Herpy McDerperson 2011-12-11 13:59

What the flying fuck is wrong with my C++ string compare?


//Stem word
string stemWord(string word)
{
    const int word_len = word.length();
    string stems[4] = {"ing","ed","er","s"};
    string temp = "";
    bool isStem;

    if (word_len > 4)
    {
        for (int i = 0; i < 4 || isStem == false; i++)
        {
            if (word.compare(word_len - stems[i].length(), stems[i].length(), stems[i]) == 0)
            {
                for (int x = 0; x < diff; x++)
                {
                    temp[x] += word[x];
                }

                word = temp;
            }      
        }
    }

    return word;
}

The word I'm sending to the is "testing," and this method is supposed to remove the stem (eg. "ing") and return the resulting stemmed word.

According to the MSDN's shitty "still, blahblah.." example (http://www.cplusplus.com/reference/string/string/compare/) this should work perfectly fine.

Name: Anonymous 2011-12-11 17:17

>>19

Yes but your code looks sloppy as fuck. You should be doing this:

string anusify(string faggot)
{
    const int anus_count = faggot.length();
    string anus = faggot;
    int finish = anus_count;
  
    if(anus_count > 4)
    {
        if(faggot[anus_count-1] == 's')
            finish = anus_count-1;
    else if( (faggot[anus_count-1] == "r" && faggot[anus_count-2] == "e" ) || (faggot[anus_count-1] == "d" && faggot[anus_count-2] == "e" ))
        finish = anus_count-2;
    else if( (faggot[anus_count-1] == "g" && faggot[anus_count-2] == "n" && faggot[anus_count-3] == "i")
        finish = anus_count-3;
        if(anus_count != faggot.length)
        {
            anus = "";
            for(int i = 0;i<anus_count;++i)
                anus[i] = faggot[i];
        }
    }
    return anus;
}

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