Thread: 2D table problem

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question 2D table problem

    I have a 2D table problem. I want to fill 2D table with some numbers but I do not know how to do it.

    Example:

    int main()
    {
    int generate;

    printf("Enter a number: ");
    scanf("%d", &generate);
    for (int i=0; i<10; i++)
    {
    for (int j=0; j<10; j++)
    {
    Table[i][j] = generate;
    printf("%d,%d\n", Table[i][j]);
    }
    }
    return 0;
    }

    With this code I only fill the the [i] part.

    What Am I missing?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    The first brace of the array is never refered to for data. It is the outer braces. That's because the first set of braces holds the index of the array of arrays-of-data. Like this:

    A
    R
    R
    A
    Y
    [0] - [0] [1] [2] [3] [4] [5] sub-array
    [1] - [0] [1] [2] [3] [4] [5] sub-array
    [2] - [0] [1] [2] [3] [4] [5] sub-array
    [3] - [0] [1] [2] [3] [4] [5] sub-array

    ----------------------------------------------

    So to access this array[3][5]<---you will get the data in this brace
    Code:
    int c = 21;
    for(i = 0; i < 3; i++)
    for(k = 0; k < 5; k++)
    {
    array[i][k] = c;
    printf("[%i][%i]: %i \n"
             "----------------\n", i, k, array[i][k]);
    c++; 
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with 2D array
    By Stlcardinal50 in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2009, 03:23 PM
  2. Problem with a 2D array.
    By earth_angel in forum C++ Programming
    Replies: 4
    Last Post: 08-20-2005, 11:28 AM
  3. rehash help
    By kashifk in forum C++ Programming
    Replies: 1
    Last Post: 10-22-2003, 06:51 PM
  4. help with operator <
    By kashifk in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2003, 03:49 PM
  5. OpenGl 2D Tiling problem
    By werdy666 in forum Game Programming
    Replies: 1
    Last Post: 09-29-2002, 11:48 PM