void trapright(char *buf,char *trapper,char *destbuf)
{
char *p;
const char *a;
for (p = buf+strlen(buf)-1;p>=buf; ) {
for ( a = trapper;*a!='\0';++a) {
if (*a == *p)
break;
}
if ( *a == *p)
p--;
else {
++p;
break;
}
}
strncpy(destbuf,buf,p-buf);
destbuf[p-buf] = '\0';
#ifdef DEBUG
fprintf(stderr,"destbuf after trapright is %s\n",destbuf);
#endif
return;
{
char *p;
const char *a;
for (p = buf+strlen(buf)-1;p>=buf; ) {
for ( a = trapper;*a!='\0';++a) {
if (*a == *p)
break;
}
if ( *a == *p)
p--;
else {
++p;
break;
}
}
strncpy(destbuf,buf,p-buf);
destbuf[p-buf] = '\0';
#ifdef DEBUG
fprintf(stderr,"destbuf after trapright is %s\n",destbuf);
#endif
return;
}
由于buf可能指向只读内存区,故将去掉空白字符的字符串保存在destbuf指向的内存中