Capitalizing certain chars in a string in C -
i'm looking way convert upper case letters lower case letters user inputted string. problem conditional ignored, , every character changed, not upper case ones. record tried converting chars ints using atoi encountered same issue above.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char letter[100]; scanf("%s", letter); int i; for(i=0; letter[i]!='\0'; i++){ if((letter[i]>='a')||(letter[i]<='z')){ letter[i]=letter[i]+32; } } printf("%s", letter); return 0; }
i suggest using library functions, islower()
, isupper()
, toupper()
, tolower()
this. in case, this:
for(i = 0; < strlen(letter); i++) { letter[i] = tolower(letter[i]); }
Comments
Post a Comment