+ 1
Hi what's wrong with this code?
//Program in C to invert case of alphabets #include <stdio.h> #include <string.h> int main() { char str[20]; scanf("%s", str); int l= strlen(str); printf("%s", str); for(int i=0; i<=l-1; i++){ printf("\n%d", str[i]); if(str[i]>=65 && str[i]<=90) str[i]= str[i]+32; if(str[i]>=97 && str[i]<=122) str[i]= str[i]-32; } printf("\n%s", str); return 0; } //Runs on compiler but the entire string is converted to upper case.
2 Respuestas
+ 2
you need a continue statement in the first if-statement to skip the rest of the loop or make second if-statement an else if.
if you invert from upper to lower case in first if-block, the second if-block will see them as lowercase and invert them back to uppercase.
+ 1
Thankyou @ Gen200
Great Lesson!!