1、strcat()

#include <windows.h>
#include <assert.h>
#include <iostream>
//strcat()函数分4部分写
//1.定义4个char*
//2.变量检查不为空assert()
//3.指针指向第一个字符串的末尾
//4.逐个字符的赋值
char *strcat(char *strDest, char *strSrc)
{
char *address = strDest;
assert( (strDest != NULL)&&(strSrc != NULL));
while(*strDest)
{
strDest++;
}
while(*strDest++ = *strSrc++)
{
;
}
return address;
} void main()
{
char l[] ="li"; //注意此处需要时开辟空间的数组
char *w = "wen";
strcat(l,w);
std::cout<<l;
}

2、strcpy()

#define  NULL 0
#include <assert.h>
#include <stdlib.h>
#include <iostream>
char * strcpy(char *strDest, char *strSrc)
{
char *address = strDest;
assert(strDest!=NULL&&strSrc!=NULL);
while (*strDest++ = *strSrc++)
{
;
}
return address;
}
void main()
{
char a[] = "li";
char *b="lwn";
strcpy(a,b);
std::cout<<a;
system("pause");
}

3、strcmp()

#include <stdlib.h>
#include <iostream>
int strcmp(const char *strDest, const char *strSrc)
{
while (*strDest == *strSrc)
{
if (*strDest =='\0') //注意时单引号
return ;
strDest++;
strSrc++;
}
return *strDest - *strSrc; }
void main()
{
char a[] = "li";
char *b="li";
strcmp(a,b);
std::cout<<strcmp(a,b);
system("pause");
}

4.strlen()  //由于strlen()函数不加头文件也能调用下文将名字改为strln()

#include <iostream>

int strln(const char *strDest)
{
int i=;
while (*strDest !='\0')
{
strDest++;i++;
}
return i;
} void main()
{
char a[] = "li4";
std::cout<<strln(a);
system("pause");
}
05-11 15:15