#include<stdio.h>
char *removedps(char *x)
{
int Ar[256] = {0};
int ip=0;
int op=0;
char temp;
while(*(x+ip))
{
temp = (*(x+ip));
if (!Ar[temp]) {
Ar[temp] = 1;
*(x+ip) = *(x+op);
op++;
}
ip++;
*(x+op) = '\0';
}
return x;
}
int main()
{
char lo[] = "0001";
printf("%s",removedps(lo));
}
我的代码不工作 我已经努力查看错误 我得到的只是第一个字符。 我的想法很简单 制作一个包含 256 个位置的数组 将零插入其中 然后为字符串中的每个字符插入 1(在数组的那个位置)
最佳答案
你的作业看起来是这里的错误。
op是“出位”,ip是“入位”
应该是这样
*(x+op) = *(x+ip);
不是相反。
关于c - 使用指针从字符串中删除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8872788/