PDA - personal digital assistant

Visualizza versione completa : InStr



Admin
25/08/2006, 01:01
// Explaination of parameters:
// 1)int dwStart - the integer number the search of the string has to start from
// 2)char *lpszSearchString - the complete string where to find the lpszFindString
// 3)char *lpszFindString - the string to search in lpszSearchString starting by "dwStart" characters
int InStr(int dwStart, LPSTR lpszSearchString, LPSTR lpszFindString)
{
int retVal = 0;
int len = strlen(lpszSearchString);
int lensub = strlen(lpszFindString);
LPSTR substr = (LPSTR)malloc(lensub + 1);
int q;
int t;
if(!len)
{
goto L0;
}
if(!lensub)
{
goto L0;
}
if(len < lensub)
{
goto L0;
}
if(dwStart < 1)
{
dwStart = 1;
}
if(len == lensub && dwStart == 1)
{
if(!strcmp(lpszSearchString, lpszFindString))
{
retVal = 1;
}
goto L0;
}
for(q = dwStart - 1; q <= len; q++)
{
if(lpszSearchString[q] == lpszFindString[0])
{
for(t = 0; t < lensub; t++)
{
substr[t] = lpszSearchString[q + t];
}
substr[t] = 0;
if(!strcmp(substr, lpszFindString))
{
retVal = q + 1;
break;
}
}
}
L0:
free(substr);
return retVal;
}