I am trying to allow the user to enter up to 26 chars in an array, and then it will go through the array, delete all the duplicate chars, and then shift everything to the right. I can load the array, but i cant seem to get the delete/shift process to work. I am having all of my troubles with the deleteRepeats. I have tried many things with varying degrees of success... below is what i have so far. Any help would be great. Thanks.
#include <iostream>
using namespace std;
void enterArray(char a[], int size, int& numberUsed);
// Size is the max size of array a
//Number Used is number of values stored in a
//a[0] - a[numberUsed-1] are all char
void deleteRepeats(char a[], int numberUsed);
int main()
{
const int max_char = 26;
char sampleArray[max_char];
int numberUsed;
enterArray(sampleArray, max_char, numberUsed);
deleteRepeats(sampleArray, numberUsed);
for (int index = 0; index < numberUsed; index++)
cout << sampleArray[index] << " ";
cout << endl;
return 0;
}
void enterArray(char a[], int size, int& numberUsed)
{
cout << "Please enter up to " << size << " characters\n" << "End the statement with a capital 'Z'\n";
char next;
int index = 0;
cin >> next;
while ((next != 'Z') && (index < size))
{
a[index] = next;
index++;
cin >> next;
}
numberUsed = index;
}
void deleteRepeats(char a[], int numberUsed)
{
int i = 0, y=1, x = 0, counter = 0;
for (int x = 0; x < (numberUsed - 1); x++)
{
for (int y = 1; y < (numberUsed); y++)
{
while(a[x] == a[y])
{
for(int i = x; i <(numberUsed -1); i++)
{
a[i] = a[i+1];
counter++;
}
a[counter] = 0;
counter = 0;
}
I actually it would shift everything to the left. I envision it would work like...
user enters:
a,a,a,a,s,d,a
and it would run though in various steps...
a,a,a,s,d,a,a
a,a,a,s,d,a
a,a,s,d,a,a
a,a,s,d,a
a,s,d,a,a
a,s,d,a
s,d,a,a
s,d,a
Then it would output the s,d,a at the end.