Xara
Xara

Reputation: 9098

Putting values in Two Dimensional Array

I am using a double pointer to make a two dimensional array.

     int **table;

the X axis of table points to Ascii values like show below: enter image description here

using the code below I fill up the table

  for (int S.no=0; S.no < 20 ; S.no++ )
              {
     for (int ASCII=0; ASCII < 255 ; ASCII++ )
              {
                table[S.no][ASCII]=value; 
               }
                                      }

SO, I get something like this:

enter image description here

Now I want to put value in table for two characters each like below:

enter image description here

Please help me what value I will put in the ASCII since now the characters are combined. Initially I was putting int ASCII for single char but now what will I do for two characters? as I cannot combine the ASCII of two characters as this will cause problem in accessing the table.

       table[S.no][ASCII]=value; 

Upvotes: 0

Views: 227

Answers (2)

Brian Gradin
Brian Gradin

Reputation: 2275

I'm not sure if this is what you are looking for, but you could add another dimension to the array:

#define NUM_VALUES 20
#define ASCII_RANGE 255

int (*table)[ASCII_RANGE][ASCII_RANGE] = new int[NUM_VALUES][ASCII_RANGE][ASCII_RANGE];

for (int S.no = 0; S.no < NUM_VALUES; S.no++) // S must be a pre-defined class...?
{
    for (int ascii1 = 0; ascii1 < ASCII_RANGE; ascii1++)
    {
        for (int ascii2= 0; ascii2 < ASCII_RANGE; ascii2++)
            table[S.no][ascii1][ascii2] = value; // value = some pre-defined value
    }
}

Upvotes: 2

user3125280
user3125280

Reputation: 2829

for (int S.no=0; S.no < 20 ; S.no++ )
    for (int ASCII=0; ASCII < 255 ; ASCII++ )
        for (int ASCII_2=0; ASCII_2 < 255 ; ASCII++)
        {
            table[S.no][ASCII << 8 + ASCII_2]=value; 
        }

Is that what you mean?

Upvotes: 0

Related Questions