Chinaunix首页 | 论坛 | 博客
  • 博客访问: 78387
  • 博文数量: 14
  • 博客积分: 1972
  • 博客等级: 上尉
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-25 13:04
文章分类

全部博文(14)

文章存档

2012年(3)

2011年(8)

2010年(3)

分类: C/C++

2011-05-30 13:09:03

  1. #include <stdio.h>
  2. #include <assert.h>
  3. #include <string.h>
  4. #define LEN    32

  5. char *strLwr(char *str);
  6. char *strUpr(char *str);

  7. int main(int argc, char *argv[])
  8. {
  9.     char ch[LEN]={"Hello"};
  10.     char newch[LEN]={0};

  11.     strcat(newch, strLwr(ch));
  12.     puts(newch);

  13.     getchar();
  14.     return 0;
  15. }

  16. /*
  17. *函数功能:将字符串转为小写
  18. *入口参数:str
  19. *出口参数:tmp
  20. */
  21. char *strLwr(char *str)
  22. {
  23.     char *tmp=str;
  24.     int i='a'-'A';
  25.     assert(str != NULL);
  26.     while(*str)
  27.     {
  28.         if(*str>='A' && *str<='Z')
  29.         {
  30.             *str=*str+i;
  31.         }
  32.         str++;
  33.     }

  34.     return tmp;
  35. }


  36. /*
  37. *函数功能:将字符串转为大写
  38. *入口参数:str
  39. *出口参数:tmp
  40. */
  41. char *strUpr(char *str)
  42. {
  43.     char *tmp=str;
  44.     int i='a'-'A';
  45.     assert(str != NULL);
  46.     while(*str)
  47.     {
  48.         if(*str>='a' && *str<='z')
  49.         {
  50.             *str=*str-i;
  51.         }
  52.         str++;
  53.     }

  54.     return tmp;
  55. }
阅读(1380) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~