0

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 ;)

Pois0nous
  • 3
  • 2
  • Get the size of the input and have a flag to if the character is it an even position or odd position and make each character letter upper/lower case accordingly – Moonhead Jun 23 '15 at 19:05
  • 4
    _"What should I do if I want it to be Decussate?"_ - Jump in front of a bus to spare everyone from having to read it. – Captain Obvlious Jun 23 '15 at 19:13
  • I think it might be a codewars question. I already saw an answer on SO in Java, but I can't find it. – rghome Jun 23 '15 at 20:27
  • possible duplicate of [Please tell me how this code works'](http://stackoverflow.com/questions/30953371/please-tell-me-how-this-code-works) – rghome Jun 23 '15 at 20:29

1 Answers1

0
 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.

Ediac
  • 833
  • 7
  • 14