Hi guys, can anyone give me a steer regarding passing arrays between functions.
I want to create an array from user input, so the size and content of the array is determined at runtime. I then want to pass the array to various functions and have it returned to main() inbetween.
So far i have something like this
1 2 3 4 5 6 7 8 9 10 11 12 13
int main()
{
FunctionToPopulateArray(); //returns array to main
for(int i=0; i<100; i++) //for each increment the function alters the
{ //values of the array.
FunctionOnArray(); //calcs are performed based on new values
calcs based on array //of the array
FunctionToOutputArray();
} //the array is passed back to main and then to
//an output function which records the current
//state of the array before the next increment
}
So my array represents a vehicle[x] of unknown number of axles. The user imputs the number of axles and attributes such as weight and location. Each axle is stored as a struct member like so.
I am looping through to increment the position of the vehicle and then perform calcs based on the new position. At each increment the position is increased for each axle and the flags indicate whether the axle is to be considered.
I am having trouble passing the array as it is declared in a function, i have managed to use pointers to the array but not been able to pass these between functions. Is there a better way to handle the problem?