2016-11-03 29 views
-1

我在下一個循環中使用了數組的i值,所以我做錯了什麼?另一個錯誤說 TicTac.c:27:15:錯誤:數組類型'int [3]'不可賦值 Matrix [i,z] = h,v; 非常感謝,如果我以錯誤的方式提出我的問題,非常抱歉。這是我在這裏的第一個問題。非常感謝 !error:expression result unused [-Werror,-Wunused-value] Matrix [i,z] = h,v;我不明白?

{  /*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"); 
        } 
      } 
} 



} 
+4

'h,v'不符合您的想法。不知道這是你唯一的問題,但沒有足夠的代碼來說明。 http://stackoverflow.com/questions/54142/how-does-the-comma-operator-work –

+0

比較什麼不工作'矩陣[我,z]'什麼'矩陣[o] [j]' 。你錯過了一些括號。 –

+0

謝謝!現在它工作了! – shesdima

回答

1

我不知道是否可以使用

Matrix[i,z] = h,v; 

你可能想使用類似

Matrix[i][z]=h; 

這可能是你的問題。

除此之外,請了解如何在C或C++中使用多維數組。

+0

謝謝!我會在我的陣列上工作,看起來像我剛纔複製工作陣列的策略是一個非常糟糕的舉動.. – shesdima

+0

你認爲這會解決你的問題嗎? –

0

Matrix[i,z] = h,v是麻煩。編譯器首先執行Matrix[z] = h,但看到一個懸掛iv。逗號會導致「序列點」......在函數參數上分隔符或在同一個語句上使用一種弱分號。法律,但如此毫無意義,你會得到一個編譯器警告。

+0

我想,我已經修復了我的數組的語法,但編譯器仍然對我大叫: \t Matrix [i] [z] = {h,v}; error:expected expression Matrix [i] [z] = {h,v}; 編譯器指出第一個支架,它是什麼意思?我的語法錯誤嗎? – shesdima

+0

Matrix [i] [z] = x將x的單個值賦給Matrix的單個值。 Matrix [i,z]是一個誤解性陳述。 C不是允許(a,b)=(1,2)將a賦值給a的語言,對b賦予2。在{大括號}中包含多個值只適用於編譯時初始化。 – Gilbert

+0

@shesdima:'Matrix [i] [z] = {h,v}' - 這是什麼意思?你想用右邊的'{h,v}'來表達什麼? – AnT