Thread: Searching an array

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    9

    Searching an array

    Hi,

    I was wondering if anybody could help me. I found some code to search an array on this message board.

    Code:
    	for( x = 0; x < arraySize; x++ )
    	{
        	          if( Note_Array[x] == note_no )
                              break;
    	}
    It all seems to work fine except that I would like to know the location in "Note_Array" that the match was found. I imagined that the value of x would be the location in the array, however the value of x doesn't seem to change.

    What am I doing wrong?

    thanks,
    Paul.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    9
    DOH!!!

    Okay sorted it out

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    9
    MMMM I retract that DOH!

    It still doesn't work properly.

    Any ideas?

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Remember that once the loop terminates, if x == arraySize then you didn't find the item.

    Also, what are Note_Array and note_no defined as?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    9
    Both declared as integers

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Well, if it's still giving you trouble, post your latest code.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    9
    Seems to be working fine now.

    The C compiler on the DSP suite I'm using seems to have a mind of its own at times.

  8. #8
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    They all do. They're like little 2 year olds. Sometimes they do what you want...
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. searching thru a c++ class array
    By stanleyw in forum C++ Programming
    Replies: 1
    Last Post: 05-29-2002, 09:15 PM