replacing caps with lower case (c++)
hi all, i'm stuck on this here and hope you guys can lend a hand
i'm supposed to write a program that watches for an accidental caps lock press that would lead to a string of characters such as 'tHIS IS THE ERROR'. what the program would do is find such occurences and fix it. ie replace the 't' with a 'T' and the remaining caps with their corresponding lower case values. this is what i have so far. this just replaces all caps with lower cases. i'm not sure how i would locate more than 1 consecutive upper case character. or how i would accept long string input from the keyboard.
thanks
#include <stdio.h>
main()
{
int i;
char z[20];
gets(z);
for(i=0; i<20; i=i+1)
{
if (z[i]>='A' && z[i]<='Z')
{
z[i]=z[i]+ 'a'-'A';
}
}
printf("%s\n",z);
getchar();
}
__________________
no man or woman is worth your tears - and the one who is, won't make you cry
question authority, don't ask why, just do it!
|