Hi, I have a homework assignment for my programming course that I'm having a lot of trouble with. The object is to take an array, and remove all of the duplicate numbers, and create another array without the dupes. Here's my code right now:
Code:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include "simpio.h"
#define size 10
int removedup(int inpArray[],int arraySize, int outArray[]);
main()
{
int inpArray[size],outArray[size],i;
printf("Enter integer values for the array");
for(i=0;i<size;i++)
inpArray[i]=GetInteger();
i=removedup(inpArray,10,outArray);
printf("%d\n",i);
for(i=0;i<size;i++)
printf("%d\t",inpArray[i]);
for(i=0;i<size;i++)
printf("%d\t",outArray[i]);
}
int removedup(int inpArray[],int arraySize, int outArray[])
{
int i,temp,j,k;
k=0;
for (i=0;i<size;i++)
{
temp=inpArray[i];
for (j=0;j<size;j++)
{
if (outArray[j]==inpArray[i])
{
b break;
}
else outArray[k]=inpArray[i];
k++;
}
}
return k;
}
The function removedup is supposed to return the size that the second array (The one without duplicates) should be, but when I run it, I always get an output of either 10, or the program terminates after the 9th cycle of i. Thanks in advance for any help.