I have already a char array which contains aphabets and space.I want to place the alphabets in another array but every alphabet or space should be put in only once and there should be no repitions.Can someone help me out?
I have already a char array which contains aphabets and space.I want to place the alphabets in another array but every alphabet or space should be put in only once and there should be no repitions.Can someone help me out?
Walk through the original array. If the current element is an alphabet, then copy it in the specific array. If it is a space, then copy it in a different array. To make sure there are no repetitions, before inserting an element into the array, check if the character to insert is not already present in the array.
Try some coding your self.
And then if you have doubt then post it here.
Because unless you try you can't understand the things.
I have done so far but no success!
[code]
for(count=0;count<total;count++) // total is total no of chars in full
{
dif_chars[count]=full[count];
for(check=count-1;check>=0;check--)
if(dif_chars[check]==dif_chars[count])
dif_chars[count]='0';
}
for(count=0;count<NUM_CHARS;count++)
if(dif_chars[count]=='0')
dif_chars[count]='\0';
dif=strlen(dif_chars); // dif is the no of distinct chars
[\code]
>>I want to place the alphabets in another array but every alphabet or space should be put in only once and there should be no repitions<<
Create an array 256 in size. Initialise all elements to 0. When you have a character, use its value to index this array, and set the array element to 1, denoting that entry as being used already. Next time round the loop (ie when you have the next character), simply check array for 0 or 1 and take the appropriate action.
Code:int ch; int DoneThese[256] = {0}; ch = getchar(); /* Or whatever input function you want */ /* Do some error checking, too ! */ if (DoneThese[ch] == 0) { /* We haven't used ch before, so use it, then mark it as being used */ ... DoneThese[ch] = 1; }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]