#include <stdio.h>
//查找后缀
bool hasEnding (char *& strFull,char*& strEnd)
{
char * pFull = strFull;
while(*pFull != 0)
pFull++;
char * pEnd = strEnd;
while(*pEnd != 0)
pEnd++;
while(1)
{
pFull--;
pEnd--;
if (*pEnd == 0)
{
break;
}
if (*pFull != *pEnd)
{
return false;
}
}
return true;
}
//查找前缀
bool hasStarting (char *& strFull,char*& strStart)
{
char * pFull = strFull;
char * pStart = strStart;
while(1)
{
if (*pFull != *pStart)
{
return false;
}
pFull++;
pStart++;
if (*pStart == 0)
{
break;
}
}
return true;
}
int main()
{
char * url = "http://jpg";
char * end = ".ajpg";
bool b = hasEnding(url,end);
char * start = "http://";
b = hasStarting(url,start);
return 0;
}
c语言字符查找前缀和后缀函数
最新推荐文章于 2023-04-23 21:36:14 发布