这是我的电话:
testFunc(0,0,"+++++A+++b+c++++d+e++++f+g+++++h+i","Abcdefghi");
到函数:
void testFunc(int isRight, int step, const char* str1, const char* str2)
{
static int testNum = 1;
printf("test%d: %d\n", testNum++, extendedSubStr(isRight, step, str1, str2));
}
那叫:
int extendedSubStr(int isRight, int gap, const char* str1, const char* str2)
{
// find location of the first char
char * pch;
char * firstOcur;
pch=strchr(str1,str2[0]);
firstOcur = pch;
int i=0;
while (pch!=NULL)
{
i++;
// find next char from the remaining string
pch=strchr(pch+1,str2[i]);
}
if(i==strlen(str2))
{
// return position of the first char
return firstOcur-str1;
}
}
当我尝试迭代str1
using strchr()
which 需要一个空终止的字符串时,我的问题就开始了。由于某种原因,它一直在循环。我宁愿不使用memchr()
.
为什么str1
并且str2
没有被归零终止?我怎样才能终止它们?