I wrote this program to convert vowels to uppercase and consonants to lowercase for a given input.Once the string is converted to uppercase its being converted to lowercase but i haven't used strlwr.here is the code..
void main()
{
char a[20], b[20], c[10] = "aeiou";
int t, n;
printf("enter the word");
gets(a);
strlwr(a);
n = strlen(a);
for(t = 0; t<n; t++)
{
if(a[t] == c[0] || a[t] == c[1])
{
strupr(a);
}
else if(a[t] == c[2] || a[t] == c[3])
{
strupr(a);
}
else if(a[t] == c[4])
{
strupr(a);
}
else
{
strlwr(a);
}
b[t] = a[t];
/*line 456*/
}
b[n] = '\0';
printf("%s", b);
}
consider the input aaasa. 1st a is con to upr,2nd a is con to lwr(since string is converted to upper in 1st loop and i haven't changed it to lowercase.),3rd a to upr, s to lwr, 4th a to upr. This is solved by placing strlwr(a) at line 456 but i want to know why uppercase is being converted to lowercase even though i haven't used strlwr anywhere in the if else blocks. please answer this.thank you in advance.
Instead of using strlwr/strupr, for changing individual characters, simply add/subtract
32
from the char for the respective operations.So, if you consider the following line:
then,
would set the value of
x
toa
.EDIT
Your entire
for
loop would be: