- 论坛徽章:
- 0
|
c和指针第六章编程第二题,题目是编写一个函数,删除一个字符串的一部分。。
答案上给的程序我有些疑问,答案如下
#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;
}
在match中已经将指针移到了匹配的字符串尾部, 而下面的while( *str++ = *next++ ) 并没有达到预期的效果啊,next应该指向第一个匹配的字符才对啊,是不是答案错了? |
|