#include <stdio.h>
#include <assert.h>
char *strcpy(char *strDest,const char *strSrc) //复制字符串
{
assert((strDest!=NULL)&&(strSrc!=NULL));
char *address = strDest;
while((*strDest++=*strSrc++)!='\0')
NULL; //空语句
return address;
}
int strcmp(const char *s1,const char * s2) //比较字符串
{
assert(s1!=NULL&&s2!=NULL);
while(*s1&&*s2&&*s1==*s2)
{
s1++;
s2++;
}
return (*s1-*s2);
}
char *strcat(char *strDes, const char *strSrc)//连接字符串
{
assert((strDes!=NULL)&&(strSrc!=NULL));
char *address = strDes;
while(*strDes!='\0') //将原字符串指针移到最后一个字符
strDes++;
while((*strDes++=*strSrc++)!='\0')
NULL;
return address;
}
int strlen(const char *str) //求字符串长度
{
assert(str!=NULL);
int len = 0;
while(*str++!='\0')
{
len++;
}
return len;
}
int main(int argc, char* argv[])
{
char a[10];
strcpy(a,"hello world");
printf("%s\n",a);
char s1[]="abcd";
char s2[]="abcd";
int res = strcmp(s1,s2);
printf("%d\n",res);
char b[]="hello";
char c[]="world";
char d[20];
strcpy(d,b);
strcat(d,c);
printf("%s\n",d);
int len = strlen(a);
printf("%d\n",len);
return 0;
}