this program is supposed to sort an input list and then remove all duplicates.
so I'm not quite sure what is wrong with my program, but the output for the original list is a very long list of the same random number(it doesn't change with the input numbers) and the output list is weird as well.
Here is the code:
/*This program removes duplicates from a sorted array of integers*/
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#include "strlib.h"
#include "math.h"
#define size 100
#define sentinel 0
void getArray(int arr[size]);
int maxCycles(int arr[size]);
void sortArray(int arr[size],int cycles);
int indexMin(int arr[size],int low,int high);
void swap(int arr[size],int loc1,int loc2);
int removedup(int inpArray[size],int inpArraySize,int outArray[size]);
/*Main Program*/
int main()
{
int inpArray[size],outArray[size];
int n,q,i;
printf("Please enter a list of integers.\n");
printf("Indicate the end of list by entering 0.\n");
getArray(inpArray);
n=maxCycles(inpArray);
sortArray(inpArray,n);
q=removedup(inpArray,n+1,outArray);
/*Print Input Array*/
printf("\nThe list you entered was:\n{");
for (i=0;i<n;i++)
{
printf("%d, ",inpArray[i]);
}
printf("%d}\n",inpArray[n+1]);
/*Print Output Array*/
printf("\nThe list without repeats is:\n{");
for (i=0;i<q-1;i++)
{
printf("%d, ",outArray[i]);
}
printf("%d}\n",outArray[q-1]);
}
void getArray(int arr[size])
{
int i,n;
n=1;
i=0;
while(n!=0)
{
printf("Enter next integer: ");
arr[i]=GetInteger();
n=arr[i];
i++;
}
}
int maxCycles(int arr[size])
{
int count,i;
count=0;
for(i=0;i<size;i++)
{
if (arr[i]!=0) count++;
}
return count;
}
void sortArray(int arr[size],int cycles)
{
int i, minInd;
for (i=0; i<3; i++)
{
minInd = indexMin (arr, i, size-1);
swap (arr,i,minInd );
}
}
int indexMin(int arr[size],int low,int high)
{
int i, minInd;
minInd=low;
for (i=low; i<=high; i++)
{
if (arr[i] < arr[minInd]) minInd =i;
}
return (minInd);
}
void swap(int arr[size],int loc1,int loc2)
{
int temp;
temp=arr [loc1];
arr [loc1]=arr[loc2];
arr [loc2] = temp;
}
int removedup(int inpArray[size],int inpArraySize,int outArray[size])
{
int i,n;
n=1;
for (i=1;i<=inpArraySize;i++)
{
if (inpArray[i]!=inpArray[i-1])
{
outArray[n-1]=inpArray[i-1];
n++;
}
}
outArray[n-1]=inpArray[i-1];
return n;
}
any help would be greatly appreciated. Thanks!