我想創建一個二維數組,其中行和列的數量是固定的,列值將從控制檯輸入中獲取。如何從C語言的一行控制檯輸入創建一個數組?
void main() {
int myArray[3][5];
int i;
int a, b, c, d, e; // for taking column values
for (i = 0; i < 3; i++) { // i represents number of rows in myArray
printf("Enter five integer values: ");
// taking 5 integer values from console input
scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
// putting values in myArray
myArray[i][1] = a;
myArray[i][2] = b;
myArray[i][3] = c;
myArray[i][4] = d;
myArray[i][5] = e;
}
// print array myArray values (this doesn't show the correct output)
for (i = 0; i < 3; i++) {
printf("%d\t %d\t %d\t %d\t %d\t", &myArray[i][1], &myArray[i][2],
&myArray[i][3], &myArray[i][4], &myArray[i][5]);
printf("\n");
}
}
當我運行此程序時,它正確地輸入輸入,但沒有按預期顯示數組輸出。我怎麼能這樣做,任何想法?請幫忙。
'&myArray的[I] [1]' - 爲什麼'&'? – Mat 2014-09-01 17:50:08