int main(int argc, char *argv[]) { char a[] = "heaheaaheheaa"; char *b = "aa"; del_substr(a, b); printf("%s", a); return 0; }
int main(void) { char *str = "ABCDEFG"; char *substr = "CDE"; int res; res = del_substr(str, substr); printf("%d\n", res); }
int main(void){ char str[100]; char sub[100]; printf("Enter the source string:"); scanf("%s", str); printf("Enter the sub string:"); scanf("%s", sub); printf("substr exists? return = %d\n", del_substr(str, (char const *)sub)); return 0; }
int main(int argc, char const *argv[]) { char str[] = "sdfsfsfesfrttreyyr";//声明为数组而非指针 printf("%s\n", str ); if ( del_substr( str , "sfe") ) { printf("%s\n", str ); }else{ printf("sdgfg\n" ); } return 0; }
int main() { char str[100]; char del[20]; int del_substr(char *str,char *substr); printf("Please input the str:"); scanf("%s",&str); printf("Please input the del str:"); scanf("%s",&del); del_substr(str,del); return 0; }
/* //#define NULL 0 #define NUL '\0' #define TRUE 1 #define FALSE 0 char * match(char *str, char *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; } */ int main(void) { int del = 0; char str[] = "abcdeghijefgklmnopqrstu"; printf("%s\n", str); del = del_substr(str, "efg"); if (del == 1) printf("%s\n", str); else printf("not find\n"); del = del_substr(str, "eg"); if (del == 1) printf("%s\n", str); else printf("not find\n"); exit(EXIT_SUCCESS); }
void post_strip_char(char* str, char alph) { int idx = 0; int len = 0; if (str == NULL) return; idx = my_strlen(str); len = idx; while (str[idx] == alph && idx != 0) idx--; del_substr(str, idx, len-1); }