0

Hello

I'm trying to make a simple function to Rot13 strings and it's not working.I ran it through my debugger and it works until it get to the top of the loop again???Then some of the chars are rot13ed and some stay the same.

void Rot13(std::string &buffer)
{
    int inc;
    
    for(inc = 0;buffer[inc] != '\0';inc++)
    {
        if(buffer[inc] >= 'a' && buffer[inc] <= 'z')
        {
            if(buffer[inc] < 'n')
            {
                buffer[inc] += 13;
            }
            
            if(buffer[inc] >= 'n')
            {
                buffer[inc] -= 13;
            }
        }
        
        if(buffer[inc] >= 'A' && buffer[inc] <= 'Z')
        {
            if(buffer[inc] < 'N')
            {
                buffer[inc] += 13;
            }
            if(buffer[inc] >= 'N')
            {
                buffer[inc] -= 13;
            }
        }
        
        else
        {
            continue;
        }
    }
}
2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by virtual008
0
void Rot13(std::string &buffer)
{
    int inc;
    
    for(inc = 0;buffer[inc] != '\0';inc++)
    {
        if(buffer[inc] >= 'a' && buffer[inc] <= 'z')
        {
            if(buffer[inc] < 'n')
            {
                buffer[inc] += 13;
            }
            
            else
            {
                buffer[inc] -= 13;
            }
        }
        
        else if(buffer[inc] >= 'A' && buffer[inc] <= 'Z')
        {
            if(buffer[inc] < 'N')
            {
                buffer[inc] += 13;
            }
            else
            {
                buffer[inc] -= 13;
            }
        }
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.