-
Writing to a 2D array
Hi, I'm slightly stuck. I have got the user to input a value which is then stored at a hard coded index within the 2D array.
eg,
Code:
printf("Enter the 1st input value: ");
scanf("%d", &array[1][2]);
After all the input values have been entered, the system applies the requested logic to the values. This results in a single interger output.
Now, this is where I'm stuck, is there a way of writing that value to an index location in the 2D array that the user specifies.
ie, where would you like store the value? Then user inputs the row and column index number. Usig scanf() this becomes the location of the value.
Any help would be great, thanks
-
You probably need to store the value in a temporary variable - unless you know the position, in which case you can of course use the same style of code you already have, but using the index the user provided [after you have validated that it's a valid position of course and not outside of the 2D array].
--
Mats
-
Code:
int x, y;
printf("Enter row: ");
scanf("%d", &x);
printf("Enter column: ");
scanf("%d", &y);
my2darray[x][y] = myvalue;
Unless I'm misinterpreting the question.
-
Fixed
Fixed, thankyou for your help