View Single Post
Old 04-19-2005, 10:21 PM   #1 (permalink)
slant eyes
Psycho
 
Location: cali
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!
slant eyes is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76