程序编译通过,运时行有错误.
dfczj 2007-06-16 11:46:29 程序编译通过,运时行有错误.
#include <stdio.h>
char* substr(char *src, char *sub)
{
char *tmp, *result;
tmp = sub;
while (1) {
while (*src == 0x20 && src++);
result = src;
while (*src++ == *tmp++ & src[-1] );
if (!tmp[-1] && (src[-1] == 0x20 || !src[-1]))
return result;
else if (tmp[-1] && src[-1] == 0x20)
;
else {
if (!src[-1])
return NULL;
while (*src++ - 0x20);
}
tmp = sub;
}
return NULL;
}
int main()
{
char *src="th is is a test";
char *sub="ihs";//如果改为src里能找到的字串,比如th is..则不会报错.
printf("%s\n",substr(src,sub));
system("pause");
return 0;
}