-
A question about arrays
Hello
My question is that is it possible for the user to decide which array element they want to input the data into.
A printf statement can ask the user which element they want to put the data into. Say an array of 9 elements is defined is it possible that user can choose to put data in the 5th element.
I would appriciate any help anybody can give me.
-
>is it possible for the user to decide which array element they want to input the data into.
Yes.
-
get the number and put into a variable, say inputnum. Let's assume the "data" is an int named mydata:
Code:
int myarray[9];
myarray[inputnum] = mydata;
-
But don't forget to check that the user doesn't supply an array element number that is out of bounds.