Capitalize lowercase in string

2

I need to do a function that takes two strings, and change both of them. But if you have a capital letter at the first, the time to convert must be lowercase. I tried to do it, but I think it's wrong inside my while . What can I do?

Note: I can not use functions from 'string.h'.

void str_troca(char origem[], char minusc[])
{   
 char aux[MAX];
    int i=0;  
    int a=1;  
    int b=0;  

    while(origem[i]!='
void str_troca(char origem[], char minusc[])
{   
 char aux[MAX];
    int i=0;  
    int a=1;  
    int b=0;  

    while(origem[i]!='%pre%')
    {
        if(origem[i]>64 && origem[i]<91)
        {
            origem[i]-32;
        }
        i++;
    }


    aux[i]=origem[i];
    origem[i]=minusc[i];
    minusc[i]=aux[i];

    printf("%s\n",minusc );
    printf("%s\n",origem );  

}  
') { if(origem[i]>64 && origem[i]<91) { origem[i]-32; } i++; } aux[i]=origem[i]; origem[i]=minusc[i]; minusc[i]=aux[i]; printf("%s\n",minusc ); printf("%s\n",origem ); }
    
asked by anonymous 14.06.2018 / 19:29

1 answer

5

You're almost right, you just made a little silly mistake. Instead:

        origem[i]-32;

Use this:

        origem[i]+=32;

That is, it was to use more instead of less and lacked the equal sign.

That said, we can make a few more suggestions. To make the code readable, replace >64 with >= 'A' and replace <91 with <= 'Z' . Thus, it is very clear that you are looking at uppercase letters and do not need to be decorating or referring to the ASCII table with arbitrary and arcane numbers. Similarly, you can use origem[i] += 'a' - 'A'; - this can, in a way, be read as "put (+) the lowercase and draw (-) the uppercase."

    
14.06.2018 / 20:07