removing dupes out of an array - pls someone explain this to me..

This is a discussion on removing dupes out of an array - pls someone explain this to me.. within the C Programming forums, part of the General Programming Boards category; I am new to programming and to C programming itself....I was wondering how do I go about removing duplicate entries ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    12

    Cool removing dupes out of an array - pls someone explain this to me..

    I am new to programming and to C programming itself....I was wondering how do I go about removing duplicate entries in an array, in most simplest code?
    for example:
    a[7] = {1,2,5,1,2,3,3}
    and I want to remove duplicates and store new entries in a anew array, say b[] that would have unique 1,2,5,3 entries only.... Please help me out I am lost here....
    :-(

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Be patient, if you post the same question twice in one day then all you will do is annoy us.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    ok you can do it like this


    a[7] is the array
    b[] is the new array

    Code:
    for(int i=0;i<7;i++)
    {
    
       for(int j=i;j<7;j++)  
           {
                        
              if(a[i]==a[j])
              cout<<"Same number detected";
              
         }
    
    }

    so here you can see which number is same.. You can now write a function copy which copies all the numbers and removes the repeated numbers..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of pointers/pointer arithmetic
    By tlpog in forum C Programming
    Replies: 18
    Last Post: 11-09-2008, 06:14 PM
  2. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 11:09 AM
  5. Pls explain how this program works...
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 01-05-2002, 08:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21