将字符串中的大写字母变成小写字母
/*字符串中大写字母变成小写,其余字符不变*/ #include <stdio.h> #include <string.h> char* mystrlwr(char *s) { char *scopy = s; while (*s) { if (*s >= 'A' && *s <= 'Z') { *s = *s + 'a' - 'A'; } s++; } return scopy; } char *mysed_strlwr(char *s) { char *scopy = s; while (*s) { if (isupper(*s)) { *s = tolower(*s); } s++; } return scopy; } int main(void) { char s[] = "HeLLowoRLD";
printf("%s\n", mystrlwr(s)); printf("%s\n", mysed_strlwr(s)); return 0; }