Printing one dimension of a 3 dimensional array

Say I have a 3 dimensional array as follows and I want to print out what I underlined,(GCT), in the following array. I tried cout<<codons[0][0]<<endl; but it is giving me the entire row rather than the first 3 chars. Sorry if my question is poorly phrased and thanks in advance.


1
2
3
4
5
char codons[2][6][3]=
{              
    {{'G','C','T'},{'G','C','C'},{'G','C','A'},{'G','C','G'}},                                 
    {{'C','G','T'},{'C','G','C'},{'C','G','A'},{'C','G','G'},{'A','G','A'},{'A','G','G'}}, 
} 
Here's an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
    char codons[3][3][3] = {{{'G','C','A'},{'C','A','G'},{'A','C','G'}},
                            {{'T','A','C'},{'C','T','C'},{'G','A','T'}},
                            {{'C','T','T'},{'A','G','G'},{'G','C','T'}}};

    for(int i = 0;i < 3;i++)
    {
        for(int i2 = 0;i2 < 3;i2++)
        {
            for(int i3 = 0;i3 < 3;i3++)
            {
                cout << codons[i][i2][i3];
            }
            cout << endl;
        }
        cout << endl;
    }

    system("PAUSE");
    return 0;
}
Last edited on
Topic archived. No new replies allowed.