c和指針第6章第二道,幫忙解釋下好嗎
#include<stdio.h>char *match( char *str, char *want );
int del_substr(char *str,char const *substr);
void main()
{
char *a="abcdefg";
char const *b="b";
printf("%d\n",del_substr(a,b));
}
char *match( char *str, char *want )
{
while( *want != '\0' )
if( *str++ != *want++ )
return NULL;
return str;
}
int del_substr(char *str,char const *substr)
{
char *next;
while( *str != '\0' )
{
next = match( str, substr );//发现一样的字符,就返回这个字符在str中的下一个位置给next
if( next != NULL )
break;
str++;
}
if( *str == '\0')
return 0;
while( *str++ = *next++ ) //那么这里的next和str应该是一样的值啊,真心的没看懂!期待给个详细的解释,谢谢了
;
return 1;
}