So I have some code that looks like this:
int a[10]; a = arrayGen(a,9);
and the arrayGen function looks like this:
int* arrayGen(int arrAddr[], int maxNum) { int counter=0; while(arrAddr[counter] != '\0') { arrAddr[counter] = gen(maxNum); counter++; } return arrAddr; }
Right now the compilier tells me ‘warning: passing argument 1 of ‘arrayGen’ makes integer from pointer without a cast’
My thinking is that I pass ‘a’, a pointer to a[0], then since the array is already created I can just fill in values for a[n] until I a[n] == ‘\0’. I think my error is that arrayGen is written to take in an array, not a pointer to one. If that’s true I’m not sure how to proceed, do I write values to addresses until the contents of one address is ‘\0’?
The basic magic here is this identity in C:
Okay, now I’ll make this be readable English.
Here’s the issue: An array name isn’t an lvalue; it can’t be assigned to. So the line you have with
is the problem. See this example:
which gives the compilation error:
You need to have a pointer, which is an lvalue, to which to assign the results.
This code, for example:
compiles fine:
Note that because of the identity at top, you can treat ip as an array if you like, as in this code:
Full example code
Just for completeness here’s my full example: