将字符串中的大写字母变成小写字母

/*字符串中大写字母变成小写,其余字符不变*/

#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;
}
posted @ 2012-12-10 10:46  helloweworld  阅读(2130)  评论(0编辑  收藏  举报