- #include <stdio.h>
- int del_substr(char *str,char const *substr);
- int main(void){
- int result=0;
- char *str="hellopnig0s";
- char *substr="ello";
- result=del_substr(str,substr);
- if(result){
- printf("The del_str has been deleted.\n");
- }else{
- puts("The string is not contain the del_str.");
- }
- }
- int del_substr(char *str,char const *substr){
- int check=0;
- while(*str!='\0'){
- if(str==*substr){
- for(;check<strlen(substr);check++){
- if(*str!=*substr){
- return 0;
- break;
- }else{
- *str=(str+strlen(substr));
- str++;
- substr++;
- }
- }
- }
- str++;
- }
- if(check=strlen(substr)-1){
- return 1;
- }
- }
本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/441372,如需转载请自行联系原作者