What is the method to remove dupplicate items from an character array??
A Sample Program is Here which take two arrays merge them and sort them please include some lines that should remove duplicates from an resulted array??
#include <stdio.h>
// A simple bubble sort
void sort(char data[], int length)
{
int end = length - 1;
for (int i = 0; i < length; ++i)
{
for (int j = 0; j < end; ++j)
{
if (data[j] > data[j+1])
{
char tmp = data[j];
data[j] = data[j+1];
data[j+1] = tmp;
}
}
--end;
}
}
int main(void)
{
char firstArray[10];
char secondArray[10];
char mergedArray[20];
int i;
int mergedIndex;
printf("Put in the first array\n");
fgets(firstArray, sizeof(firstArray), stdin);
printf("Put in the second array\n");
fgets(secondArray, sizeof(secondArray), stdin);
// Copy the first array into the merged array
for(i = 0; firstArray[i] != '\n'; ++i)
{
mergedArray[i] = firstArray[i];
}
mergedIndex = i;
for(i = 0; secondArray[i] != '\n'; ++i)
{
mergedArray[mergedIndex++] = secondArray[i];
}
mergedArray[mergedIndex] = 0;
sort(mergedArray, mergedIndex);
printf("Merged array is '%s'\n", mergedArray);
return 0;
}
Thanks inAdvance