c - 如何在取消重复变量的同时将一个数组更改为另一个数组?

标签 c

我是编程新手,接到的任务是创建一个函数,将一个数组放入另一个数组中,并满足以下条件:目标数组中的变量仅重复一次,并且源数组和目标数组将属于大小相同。 我想出的函数是:

int RemoveDup (int src[],int dst[]) 
//recive two array compare them and copy the src array to dst,and only the none reacuring 
//numbers,the arrays must be from the same size

{
int size_src;
int size_dst;
int i,n=0;
size_src = sizeof(src)/sizeof(int);//determine the size of source array
size_dst = sizeof(dst)/sizeof(int);//determine the size of destination array
if (size_src = size_dst);//checks that the array are in the same size
{
for(i = 0;i < size_src;i++)//the loop for advancing the copying process
{
dst[i] = src[i];
}
while (i<size_dst)
{
dst[i] = dst[i++];

if (dst[i] = dst[i++])//relay on the fact that if the function will find a similar varibale, the tested varibale will be set to 0 and the other one will come out clean in the check
dst[i] = 0;//eliminating the varibale in that specific address
}
}


return dst [i];

但它似乎不起作用,也不知道哪里出了问题。 任何帮助或线索将不胜感激。

最佳答案

我注意到您在以 int src[] 作为参数的函数中使用了 sizeof(src) 。这并不是在做你认为它正在做的事情。在 C 中,数组的大小不会与数组本身一起传递给函数(与您可能熟悉的其他一些语言不同)。您必须将实际大小作为单独的参数传递。

此外,一些 printf() 语句肯定会对您的调试工作有所帮助。确保值(value)观是你认为应该的。希望您能够访问交互式调试器,这可能对您也非常有用。

关于c - 如何在取消重复变量的同时将一个数组更改为另一个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4485216/

相关文章:

c - 如何更高效地编写程序

c - 为什么这个错误: incompatible pointer to integer conversion?

c - 如何使用结构体接收用户输入以传递给另一个方法?

c - Binary Buddies 实现问题

c - 如何解决CUDA中的 "expected an identifier"错误

c -\b 和\r 在 C 中的用法

c++ - c 和 c++ 中 sizeof 运算符的工作是否不同

c - 用于父子信号的 waitpid

c - 是否可以从 OCaml 调用 C 函数并有效地传递一个巨大的数组?

c - 我对链表感到困惑。解决方案是什么?