Convert String to Uppercase Decussate in C++

166 views Asked by At

I have this code:

        Str UpperCase()
    {
        Str Result;
        int i = 0;
        for (; string[i]; i++)
        {
            if (string[i] <= 'z' && string[i] >= 'a')
            {
                string[i] -= 32;
            }
            Result.string[i] = string[i];
        }
        Result.string[i] = 0;
        return Result;
    }

It will make String Uppercase. What should I do if I want it to be Decussate? Example: hi my name is pooya ==> Hi My NaMe Is PoOyA

Sorry for my bad english and Thanks ;)

1

There are 1 answers

0
Ediac On BEST ANSWER
 Str UpperCase()
    {
        Str Result;
        int i = 0;
        int decussate = 0;
        for (; string[i]; i++)
        {
            if (string[i] <= 'z' && string[i] >= 'a')
            {
                decussate++;
                if( decussate%2 == 1 ){
                    string[i] -= 32;
                }
            }
            Result.string[i] = string[i];
        }
        Result.string[i] = 0;
        return Result;
    }

Add int decussate, by changing it between an odd and an even number everytime a lowercase letter is found, it will create a pattern in which the 1,3,5,7,and so on letters will be capitalized, assuming the string is in lowercase.