/*
* 如果字符串 "substr" 出现在 "str" 中,则在 "str" 中删除它。
* If the string "substr" appears in "str", delete it.
* 2010-11-20
* got it
*/
#define NULL 0 /* null pointer */ #define NUL '\0' /* null byte */ #define TRUE 1 #define FALSE 0
/* * see if the substring beginning at 'str' matches the string 'want'. * if so,return a pionter to the first character in 'str' after the match. */ char *match( char *str, char *want ) { /* * Keep looking while there are more characters in 'want'. * we fall out of the loop, if we get a match. */ 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; }
|
阅读(1291) | 评论(0) | 转发(0) |