#include <stdio.h>
#define MAXLINE 4096
void rmsame(char *to, const char *from, const char same)
{
const char *tmp = from + 1;
for(; *from != '\0'; from++, tmp++) {
if ((*tmp == *from) && (*from == same)) {
continue;
}
*to++ = *from;
}
*to++ = '\0';
}
int main(int argc, char *argv[])
{
char result[MAXLINE];
rmsame(result, argv[1], *argv[2]);
printf("result = %s\n", result);
return 0;
}
测试结果如下:
cheny@cheny-laptop:~/string$ ./rmsame aabbaaccaaa a
result = abbacca
删除字符串里面相连的指定字符,例如aabbaaccaaa所有相连的a都删掉,结果就是abbacca,写的不好请大家指正,谢谢了!