strncpy,strncat要注意最后加'\0'
char *strcpy(char *des,const char *src)
{
if(des==NULL || src==NULL)
return NULL;
char *p=des;
while((*des++=*src++)!='\0');
return p;
}
char *strncpy(char *des,const char* src,int n)
{
if(des==NULL || src==NULL)
return NULL;
char *p=des;
while(n>0 && *src!='\0')
{
n--;
*des++=*src++;
}
*des='\0';
return p;
}
int strcmp(const char *s,const char *t)
{
if(s==NULL || t==NULL)
return -99999;
while(*s!='\0' && *t!='\0' && *s==*t)
{
s++;
t++;
}
return (*s-*t);
}
int strncmp(const char *s,const char *t,int n)
{
while(--n>0 && *s && *t && *s==*t)
{
s++;
t++;
}
return (*s-*t);
}
char *strcat(char *des,char *str)
{
if(des==NULL || str==NULL)
return NULL;
char *p=des;
while(*des!='\0')
des++;
while( (*des++=*str++)!='\0');
return p;
}
char *strncat(char *des,char *str,int n)
{
if(des==NULL && str==NULL)
return NULL;
char *p=des;
while(*des!='\0')
des++;
while(n>0 && *str!='\0')
{
n--;
*des++=*str++;
}
*des='\0';
return p;
}
int strlen(char *p)
{
int len=0;
while(*p++!='\0')
{
len++;
}
return len;
}