I think my wording may not be entirely accurate but please bear with me.
What I'm trying to do is write code that allows a user to input any amount of numbers and store them in an array for use at another piece of the code. However I think I'm struggling with how to use pointers correctly in order to achieve that. Here's the code I have at the moment:
int n = 0, marks[] = {0};
while (EOF != scanf("%d", marks+n))
{
n++;
int marks[n]=marks;
}
int *i_p=marks;
Unfortunately I can't initialise the variable size array with my version of C ("error: variable-sized object may not be initialised") and I don't know how else to do it. What should I change and how to make this program work correctly?
Note: this question was an exercise for school and while I read some answers to other questions using calloc/malloc, we are not expected to know or use this, so I would prefer a different solution if possible.
int vla[n] = { 0 };will not compile. (Purely as a side note, since this is not really essential to the root of the OP's problem.)