By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,604 Members | 1,414 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,604 IT Pros & Developers. It's quick & easy.

find different number of character

P: 51
Hi! could please tell me how can I get the diffetent characters of a certain array. for example in the array L = "nnbaaa"; and need to get from L the characters n, a and b and store in another array K = "nab", because n,a, and b are the diffetent chacters in L. thank you for your help.

Best Regards
Nov 12 '06 #1
Share this Question
Share on Google+
7 Replies


Banfa
Expert Mod 5K+
P: 8,916
Have you input and your result, examine every character of input in turn and if that character is not already in result add it to result.
Nov 13 '06 #2

P: 51
Hi Banfa! Yes I understood what you said. so I have to get each character in the input and then make a loop to see if this character is already in result. but the problem is that I don't know the lenght of resul. so how can I make the loop. thanks for your help
Nov 13 '06 #3

100+
P: 141
hi,

u can make a loop until u get the new line character('\n')
char str;
while(str!='\n')
{

//logic u write here

}









Hi Banfa! Yes I understood what you said. so I have to get each character in the input and then make a loop to see if this character is already in result. but the problem is that I don't know the lenght of resul. so how can I make the loop. thanks for your help
Nov 13 '06 #4

P: 51
Thank you very much for your help. could you please tell me how can I get the number of different character if L. for example L = "nnbaaa", So the number of different characters is 3, because of n, b and a. how can I get this number in a efficient way. thank you
Nov 13 '06 #5

P: 51
Please I did not understant the loop. could please explain a little bit more. thanks
Nov 13 '06 #6

Banfa
Expert Mod 5K+
P: 8,916
I don't know the lenght of resul.
You do know the length of result, it starts at 0 and everytime you add a character to it in increases by 1.
Nov 13 '06 #7

P: 51
Could you please help me with the loop, because I did it this way, and it is not working:

char L[] = "rdarcaaaabb";
short int lengthK = 1;
char K[];

K[0] = L[0];

for (int f = 1; f < 11; f++){
x = L[f];
for (int z = 0; z < lengthK; z++){
if (x == K[z])
bandera = 0;
else
bandera = 1;

}
lengthK++;
if (bandera = 1)
K[f] = x;

}
Nov 13 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.