Thread: ignoring repitions

  1. #1
    BEEP BEEP
    Guest

    Unhappy ignoring repitions

    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?

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    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.

  3. #3
    Registered User Dev's Avatar
    Join Date
    Mar 2003
    Posts
    59
    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.

  4. #4
    BEEP BEEP
    Guest

    Unhappy my effort!

    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]

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>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]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-03-2009, 04:16 PM
  2. Sort a string vector ignoring case
    By jw232 in forum C++ Programming
    Replies: 6
    Last Post: 02-01-2008, 01:37 AM
  3. Ignoring spaces...
    By alvifarooq in forum C++ Programming
    Replies: 4
    Last Post: 11-05-2004, 12:30 AM
  4. Ignoring input.
    By Vicious in forum C++ Programming
    Replies: 11
    Last Post: 10-17-2004, 04:31 PM
  5. Ignoring the Tab at the begining of the line..
    By NANO in forum C++ Programming
    Replies: 8
    Last Post: 05-03-2003, 10:56 PM