-1

I've used the i value of the array in the next loop, so what am i doing wrong ? Another error says TicTac.c:27:15: error: array type 'int [3]' is not assignable Matrix[i,z] = h,v; Thank you so much, and sorry if i ask my question in a wrong way. it is my first question in here. Thank you so much !

{     /*The tic tac board*/
int Matrix[3][3] = { {6,6,6},
                     {6,6,6},
                     {6,6,6}  };

 /*asks user for input and gives value into the array*/

for (int z = 0; z <= 2; ++z) {

for ( int i = 0; i <= 2; ++i)
 {
    printf("Give me your choice in the horizontal layer");
    int h = GetInt();
    printf("Give me your choice in the verticle layer");
    int v = GetInt();


    Matrix[i,z] = h,v;
    /*demonstrates the board*/
    for(int o = 0; o <= 2; o++)
            {

                 for(int j = 0; j <= 2; j++)
                  {
                   printf("%d ", Matrix[o][j]);
                   printf("\n");
                  }
             }  
 } 



}
prospero
  • 1
  • 3
  • 4
    `h,v` doesn't do what you think it does. Not sure if that's your only issue though, not enough code to tell. http://stackoverflow.com/questions/54142/how-does-the-comma-operator-work – Retired Ninja Nov 03 '16 at 23:45
  • Compare what doesn't work `Matrix[i,z]` to what does `Matrix[o][j]`. You're missing some brackets. – Retired Ninja Nov 04 '16 at 00:00

2 Answers2

1

I am not sure if you can use

Matrix[i,z] = h,v;

You might want to use something like

Matrix[i][z]=h;

This might be your problem.

In addition to that, please understand how to use multidimensional arrays in C or C++.

Vraj Pandya
  • 591
  • 1
  • 9
  • 13
0

Matrix[i,z] = h,v is the trouble. The compiler first does a Matrix[z] = h but sees a dangling i and v. The comma causes a "sequence point"... either delimiters on function arguments or a kind of weak semi-colon on the same statement. Legal, but so pointless you get a compiler warning.

Gilbert
  • 3,740
  • 17
  • 19
  • I think, i have fixed the syntax of my array, but the compiler still yells at me: Matrix[i][z] = {h,v} ; error: expected expression Matrix[i][z] = {h,v} ; The compiler pinpoints the first bracket, what does it mean ? Is my syntax still wrong ? – prospero Nov 04 '16 at 00:25
  • Matrix[i][z] = x assigns a single value of x to a single value of Matrix. Matrix[i,z] is a misconstructed statement. C is NOT a language allowing (a,b) = (1,2) to assign 1 to a and 2 to b. Wrapping multiple values in {braces} is only good for compile-time initialization. – Gilbert Nov 04 '16 at 00:31
  • @shesdima: `Matrix[i][z] = {h,v}` - what is that supposed to mean? What are you trying to say by that `{h,v}` on the right-hand side? – AnT stands with Russia Nov 04 '16 at 01:22
  • Matrix[i][z] = {h,v} is invalid. I was using syntax from the original post. – Gilbert Nov 04 '16 at 01:29