int del_substr(char *str, char const *substr)
{
int hasSubStr = 0;
int offset = 0;
int del_position = 0;
while(*(str + del_position) != '\0')
{
offset = 0;
while(*(substr + offset)!= '\0' ){
if(*(substr + offset) != *(str + del_position + offset)){
del_position++;
break;
}
offset++;
}
if(*(substr + offset)== '\0'){
hasSubStr = 1;
break;
} else {
hasSubStr = 0;
}
}
printf("str = %s, substr = %s \n",str, substr);
int i = 0;
do{
*(str+del_position + i) = *(str + del_position + offset + i);
}while(*(str + del_position + offset + i++) != '\0');
printf("str final = %s \n",str);
return hasSubStr;
}
亲测有效