Thread: number of occurences

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    99

    number of occurences

    Hi guys, something must be wrong with my logic here... I am trying to find the number of occurences of all the numbers from my array. Basically, I have one array filled with numbers, and I am creating another one with occurences. I thought this way:
    Code:
    for(i = 0; i < SIZE; i++)
         {
           search = numbers[i];
           
           for(j = 0; j < SIZE; j++)
               {
                 if(numbers[j] = search)
                    occurences[i]++;
               }
          }
    So, I'm taking the first number, and check whether it is repeated in the rest of the array. If it is, the loop adds one to the occurences array with the same subscript as the number I was just looking at.
    However, the results I am getting is 100 (the size of my arrays) filled in every cell of my occurences array. I messed it up somewhere in the loops. Where?

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    >if(numbers[j] = search)

    That's assignment, not comparison. Should be:-

    if(numbers[j] == search)

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    99
    I did it again? Oh my... Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  2. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 01:03 AM
  3. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  4. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 01:10 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM