我必须使用指针和函数从字符数组中消除重复项。 我无法让它正常工作:
void del_copy(char *p){
int n = strlen(p);
for (int i = 0; i < n; i++){ // Element that we compare
for (int j = i + 1; j < n;j++){ //We compare p + i element with the rest of the elements
if (*(p + i) == *(p + j)){ //If we find two similar, we eliminate that element by shifting
for (int k = i; k < n; k++)
*(p + k) = *(p + k + 1);
}
}
}
}
最佳答案
在你做一个转变后,长度会改变。但是您的 n 没有考虑到这一点。
关于c++ - 从字符数组中消除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27611432/