I would make it a c-string for now and avoid the loop to print it.
Also, you ask for 20 but its 19 long, so those correcitons look like:
const char MAXALPHA = 21; //20, as asked for, and +1 to c-string it, because you need a zero value.
char alphas[MAXALPHA]; //be sure to loop from 0 to < maxalpha. NOT <= .
alphas[20] = 0; //c-string end of string marker.
then you can remove that loop and say:
cout << "The original array is " << alphas << endl;
and then down in the testfunction:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
void testFunction(char values[], int size){
int i;
char letter;
bool repeats[256] = {false};
cout << "Enter 20 alphabets " << endl;
for (i=0; i < size; i++){
cin >> letter;
if (repeats[letter])
{
cout << "Duplicate element " << values[i] << endl;
}
else
{
values[i] = letter;
repeats[letter] = true;
}
}
}
|
what this does is every time you get a letter, it marks it as gotten from a pool of all the possible (8-bit chars). If you get it again, it finds it as used in the pool and complains.