#include "stdafx.h"
int StrLen(const char *pStr)
{
int nSize = 0;
if (NULL != pStr)
{
char *pStrTemp = (char*)pStr;
while (*pStrTemp != '\0')
{
nSize++;
pStrTemp++;
}
}
return nSize;
}
bool StrCmp(const char* pStr1, const char*pStr2)
{
if (NULL != pStr1 && NULL != pStr2)
{
if (StrLen((char *)pStr1) == StrLen((char*)pStr2))
{
char *pStrTemp1 = (char *)pStr1;
char *pStrTemp2 = (char *)pStr2;
while (*pStrTemp1 != '\0')
{
if (*pStrTemp1 == *pStrTemp2) {
pStrTemp1++;
pStrTemp2++;
}
else
{
return false;
}
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
void StrCpy(char *pStrDest, const char *pStrSrc)
{
if (NULL != pStrDest && NULL != pStrSrc)
{
char *pStrSrcTemp = (char*)pStrSrc;
char *pStrDestTemp = pStrDest;
while (*pStrDestTemp = *pStrSrcTemp)
{
if (*pStrSrcTemp == '\0') {
break;
}
pStrDestTemp++;
pStrSrcTemp++;
}
}
}
char* StrCat(char *pStrDest,const char *pStrSrc)
{
if (NULL != pStrDest && NULL != pStrSrc)
{
char *pStrDestTemp = pStrDest;
char *pStrSrcTemp = (char*)pStrSrc;
while (*pStrDestTemp != '\0')
{
pStrDestTemp++;
}
while (*pStrSrcTemp != '\0')
{
*pStrDestTemp = *pStrSrcTemp;
pStrDestTemp++;
pStrSrcTemp++;
}
++pStrDestTemp = '\0';
return pStrDest;
}
else
{
return NULL;
}
}
测试结果如下:
#include "stdafx.h"
#include "MyStr.h"
int main()
{
cout <
cout <
cout <
cout <
char szName[100] = "";
StrCpy(szName, "I am LiuDehua!");
cout <
cout <
cout <
return 0;
}
https://blog.csdn.net/lisonglisonglisong/article/details/44278013