代码来源C和指针课后答案6.2,增加主函数
#include<stdio.h>
#define NUL '\0'
#define TRUE 1
#define FALSE 0
int del_substr(char *str,char const *substr);
int main(void)
{
char *str="abcdefg";
char const *substr="de";
int a;
a=del_substr(str,substr);
printf("%d",a);
return 0;
}
char *match(char *str,char const *want)
{
while(*want!=NUL)
if(*str++ != *want++)
return NULL;
return str;
}
int del_substr(char *str,char const *substr)
{
char *next;
while(*str!=NUL)
{
next=match(str,substr);
if(next!=NULL)
break;
str++;
}
if(*str==NUL)
return FALSE;
while(*str++ = *next++)
;
return TRUE;
}