Question on arrays.

This is a discussion on Question on arrays. within the C++ Programming forums, part of the General Programming Boards category; float array[100]; Is there a way to take the array above a use the [100] in sequence? such as a ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    Question on arrays.

    float array[100];

    Is there a way to take the array above a use the [100] in sequence? such as a having it check to see if [0] is used and if so then move on to [1] and so on...

    any help would be appreciated.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Your question is confusing. You can use a for loop from 0 to 99 to access each element in the array in sequence. You could keep an extra variable to store how many in the array are used and stop when you hit that variable. You could also initialize the values to some number that you will never use and if the value is still that number when you loop through then you know the element is not being used (assuming there is a number like 0.0f that you don't need).

    You could also use a vector and only fill it with the values that you need - so if you are only using 27 elements, only add 27 elements, and if you need to use one more, just push_back a new one.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    128
    I've opted to use vectors and maps for anything that is variable in size or is primarily a lookup for medium-large lists of information. I've used vectors that had only one dimension, like a vector of strings, and I've used vectors that were struct-based. Adding items is easy, searching for items is easy, it's all easy. For what it's worth, if you've never worked with vectors, try it this time in place of your array.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Floats usually have NaN values, which you can get with numeric_limits.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about arrays.
    By Kelvie in forum C++ Programming
    Replies: 3
    Last Post: 09-17-2007, 05:32 AM
  2. A question concerning character arrays
    By ellipses in forum C Programming
    Replies: 3
    Last Post: 03-08-2005, 07:24 PM
  3. Replies: 6
    Last Post: 04-26-2004, 10:02 PM
  4. Question about char arrays
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 12:44 AM
  5. Question about arrays?? PLease read..
    By foofoo in forum C Programming
    Replies: 3
    Last Post: 06-24-2002, 02:40 PM

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