69,373
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int
my_isupper(char c)
{
return (c >= 'A' && c <= 'Z');
}
int
my_islower(char c)
{
return (c >= 'a' && c <= 'z');
}
int
my_toupper(char c)
{
if (my_islower(c))
return 'A' + (c - 'a');
else
return c;
}
int
my_tolower(char c)
{
if (my_isupper(c))
return 'a' + (c - 'A');
else
return c;
}
char *strupper(char *s)
{
char *p;
for (p = s; *p; ++p)
*p = my_toupper(*p);
return s;
}
char *strlower(char *s)
{
char *p;
for (p = s; *p; ++p)
*p = my_tolower(*p);
return s;
}
int
main(int argc, char *argv[])
{
char s[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcd-1234";
printf("%s\n", strupper(s));
printf("%s\n", strlower(s));
return 0;
}
/*************************************************************************
> File Name: toupper.c
> Author: Jukay
> Mail: hellojukay@gmail.com
> Created Time: 2014年10月23日 星期四 10时33分57秒
************************************************************************/
#include<stdio.h>
#include<ctype.h>
int main()
{
char s[] = "hello world!";
printf("before toupper is: %s\n",s);
for(int i=0; i< sizeof(s); i++)
s[i] = toupper(s[i]);
printf("after toupper is: %s\n",s);
return 0;
}
详情可登陆www.gfsoso.com