Sorting out duplicates from 2 different char arrays.

I'm struggling with an assignment for my class where we have to take input from the user into a char array. Then remove the duplicate letters from that array and take the new word and compare it another char array consisting of the alphabet. Comparing the array of the modified array (word) with the alphabet array (abc) to remove the repeated letters from the list.
Then putting the final result into another array to display everything like the example below.

For example:

The word HELLO would first become HELO then after comparing to the alphabet the end output from the new array should be HELOABCDFGIJKMNPQRSTUVXYZ.

I'm stuck more on the comparing the new word to the alphabet really.two arrays really.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
char word[20], newAbc[40] = { '/0' }; 
char abc[27] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; 
int i = 0, b = 1, n = 0, leng, dup; 
//dup counts up the repeats but is established in the first portion of the program but i've excluded it as it works perfectly.

cout << "Please enter a word: "; 
cin >> word; 

leng = strlen(word); 
 
b = 0; 
n = leng - dup; 
i = 0; 
 
for (i = 0; i < n; i++) 
{ 
for (b = 0; b < 27; b++) 
{ 
if (newAbc[i] != abc[b]) 
{ 
newAbc[n] = abc[b]; 
n++; 
} 
} 
} 
 
for (i = 0; i < 27; i++) 
cout << newAbc[i]; 
cout << endl; 
 
return 0; 
} 


I'd appreciate any kind of insight on my mistakes.
Last edited on
Not sure if I'm understanding what you mean, but you can use a find algorithm to take out any duplicates.
I'm not familiar with the find algorithm personally, but it would be able to compare two arrays?
Topic archived. No new replies allowed.