Hi,

I am a first year uni student. I am practising for an exam, so I decided to try to write some C++ code that takes an input as a string, and creates a new array with all the duplicate entries removed.

So for example, if I took an input into an array, and it was {f,a,n,t,a,s,t,i,c} it would create a new array {f,a,n,t,s,i,c}

The code that I tried using compiles, but doesn't work.

string keynodupes;

// Place first letter from keyword into new array.
keynodupes[0] = keyword[0];

for(i=1;i<keyword.length();i++){

for(j=(i-1);j>=0;j--){
if(keyword[i] = keyword[j]){
flag=1;
}
}

if(flag == 0){
keynodupes[counter] = keynodupes[i];
counter++;
flag=0;
}
}
I delcated keynodupes and keyword as strings. i.e.

string keyword;
sting keynodupes;

i'm not sure if maybe i should have done char[] keyword, or if there is a logic problem or what. i wasn't sure what length to make the keynodupes array if i did that...

I included the <string.h> library.

Any help would be greatly appreicated. Thanks!