I am trying to make a function that cleans out my duplicates of number in my array, but it seems that i cant figure out what i am missing to just remove the duplicate. Just to make it more clear: The function should not become void.
[1,2,3,3,4] -> [1,2,3,4]
[4,2,5,1]->[4,2,5,1]
[32,21,2,5,2,1,21,4]->[32,21,2,5,1,4]
It should not be empty spaces in my array, and the function should return the unique elements in the cleaned array, where cleaned is defined as "non-duplication of integer numbers"
#include <stdio.h>
int generateUniqeList(int *list, int length);
int main()
{
int list[6] = { 5, 5, 4, 3, 2, 1 };
int duplicate = generateUniqeList(list, 6);
for (int i = 0; i < 6; i++)
{
printf("%d\n", list[i] - 1); //Here i am able to change the value of the duplicates with the - 1
}
getchar();
return 0;
}
int generateUniqeList(int *list, int length)
{
int duplicate = 0;
for (int i = 0; i < length; i++)
{
if (list[i] == list[i])
duplicate = list[i];
}
return duplicate;
}