samedi 4 avril 2020

C++ matrix initialization

I want to initialize matrix accesing index, but it takes values from memory. How could i do that?

int asci[120][6];

    for(int i = 0 ;i<120;i++)
        for(int j = 0; j<6;j++)
            asci[i][j] = 2;

   // asci[94][0]=3;
    asci[94][1]=4;
    asci[94][2]=5;
    asci[94][3]=6;
    asci[94][4]=7;
    asci[94][5]=8;

    asci[118][0]=+1;asci[94][1]=-1;asci[94][2]=+1;asci[94][3]=+1;asci[94][4]=+1;asci[94][5]=0;
    asci[60][0]=-1;asci[94][1]=-1;asci[94][2]=+1;asci[94][3]=-1;asci[94][4]=0;asci[94][5]=-1;
    asci[62][0]=-1;asci[94][1]=+1;asci[94][2]=0;asci[94][3]=+1;asci[94][4]=+1;asci[94][5]=+1;

    for(int i = 0 ;i<120;i++){
        for(int j = 0; j<6;j++){
            cout<<"["<<i<<"]"<<"["<<j<<"]"<<asci[i][j];
            cout<<endl;
        }
        cout<<endl;
    }

enter image description here

Aucun commentaire:

Enregistrer un commentaire