Thread: array

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    4

    array

    How can I put a range of numbers in an array without typing in all the numbers. Like 0-24,25-49,50-74,75-100

    I tried;

    Code:
    int x[] = {0-24,25-49,50-74,75-100};
    Is that a legal statement?

    any sugguestions?

    Thanks

  2. #2
    root
    Join Date
    Sep 2003
    Posts
    232
    >How can I put a range of numbers in an array without typing in all the numbers. Like 0-24,25-49,50-74,75-100
    You don't. Try either building a vector at runtime or using paired numbers for the minimum and maximum of the range:
    Code:
    int x[] = {
            0,  24,
            25, 49,
            50, 74,
            75, 100,
    };
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Hey twm - chill on the sig man. Most people here are very cool and some of the best people you'll ever meet on a board. It's all good.


    Usually you load an array from disk if you have a lot of numbers to put into it. Unfortunately there is no DATA like BASIC keyword that allows you to put data directly into the data segment and then retrieve it with a READ.

  4. #4
    root
    Join Date
    Sep 2003
    Posts
    232
    >Hey twm - chill on the sig man.
    Joke...funny...laugh.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  5. #5
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    I'm not sure if this is what you wanted, but uhm, for loop?
    Code:
    for(int i =0; i < max; ++i)
      array[i] = i;
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You could use a 2d array, something like:
    Code:
    int array[4][25] ;
    for (int x=0;x<4;x++)
     for(int y=0;y<25;y++)
       array[x][y] = y*(x+1);
    Note I didn't test this code
    Last edited by JaWiB; 10-31-2003 at 09:06 PM.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM