Chinaunix首页 | 论坛 | 博客
  • 博客访问: 608782
  • 博文数量: 262
  • 博客积分: 8433
  • 博客等级: 中将
  • 技术积分: 2141
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-31 09:37
文章分类

全部博文(262)

文章存档

2012年(1)

2011年(168)

2010年(92)

2009年(1)

分类: 嵌入式

2011-01-14 17:15:48

  1. #include <stdio.h>
  2. #include <stdlib.h>

  3. //strcpy
  4. char* strcpy(char* dest,const char* src)
  5. {
  6.     char* tmp = dest;
  7.     while((*dest++ = *src++) != '\0')
  8.         ;
  9.     return tmp;
  10. }

  11. //strcmp
  12. int strcmp(const char* cs,const char* ts)
  13. {
  14.     register signed char res;    //register声明,尽量存到cpu内部寄存器
  15.     while(1)
  16.     {
  17.         if((res=*cs-*ts++)!=0||!*cs++)    //!*cs++说明一个字符串结束符:'\0'或者是 0
  18.             break;
  19.     }
  20.     return res;
  21. }

  22. int main()
  23. {
  24.     char* a = "abcd";
  25.     char b[256];

  26.     //string copy
  27.     strcpy(b,a);
  28.     printf("string a is %s! \n",a);
  29.     printf("string b is %s! \n",b);

  30.     if(!strcmp(a,b))
  31.         printf("a is equeue with b! \n");
  32.     else
  33.         printf("a is not equeue with b! \n");

  34.     return 0;
  35. }
阅读(836) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~