char* Daoxu(char *szChar)
{
assert(szChar != NULL);
char *temp = szChar;
int len = strlen(szChar);
if (len == 0 || len == 1)
{
return temp;
}
else
{
for (int i=0; i<len/2; i++)
{
std::swap(szChar[i], szChar[len-1-i]);
}
return temp;
}
}
int FindString(char *pCompared, const char *pStand)
{
assert( (pCompared != NULL) && (pStand != NULL) );
assert( !( strlen(pCompared) < strlen(pStand) ) );
int lenofcmp = strlen(pCompared);
int lenofstd = strlen(pStand);
char *temp = (char*)malloc(lenofcmp+1);
memset(temp, 0, lenofcmp);
int total = 0;
for (int i=0; i<lenofcmp; i++)
{
if ( (lenofcmp-i) < lenofstd )
{
return total;
}
memcpy(temp, pCompared+i, lenofstd);
if (strcmp(temp, pStand) == 0)
{
++total;
}
}
return total;
}
字符串倒序,以及查找 !
最新推荐文章于 2024-01-19 11:22:00 发布