Turn lowercase into string

Asked

Viewed 1,360 times

2

I need to do a function that takes two strings, and switch places both. But if you have a capital letter in the first one, at the time of converting you need to go to lowercase. I tried to do, only I think it’s wrong inside of mine while. What can I do?

Note: I cannot use string functions. h'.

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

    while(origem[i]!='\0')
    {
        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 );  

}  

1 answer

6


You almost got it right, you just made a silly little 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, you can make a few more suggestions. To make the code readable, replace >64 for >= 'A' and replace <91 for <= 'Z'. Thus, it is clear that you are looking at capital letters and do not need to decorate or consult the ASCII table with arbitrary and arcane numbers. Similarly, you can use origem[i] += 'a' - 'A'; - this can, in a certain way, be read as "put (+) the lower case and take (-) the upper case".

  • our, error beast kkkk. Vlw bro, helped mto kkk

  • Good your tip from >='A' but have to be careful to put single quotes and not double quote.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.