This should help you with your problem.
When you pass an array to a function, it decays to a pointer. A pointer is just something that points to a memory address. If you pass a pointer to a function, you are passing the memory address of that variable, so you can actually go to that memory address and modify it. So if you pass a pointer to a variable from our main function, and modify the data at that pointer in another function, the variable in our main function will be effected.
You declare arrays like this:
Code:
type name[MAX_LENGTH];
so
perhaps in your case.
Note this:
Your array can contain five floats. That is, data[0] through data[4]. That does not include data[5].
You still, of course, need to do the "error checking" and whatnot for the function.
Code:
#include <stdio.h>
#define MAX 5
void input_array(float data[]); //function prototype
int main(void)
{
float data1[MAX];
float data2[MAX];
float data3[MAX];
input_array(data1);
//Now we can access user-inputted data from main.. Ex:
printf("From main - data1[0] = %f\n", data1[0]);
return 0;
}
void input_array(float data[])
{
int i;
printf("Please input your data one at a time\n");
for(i = 0; i < MAX; i++)
{
printf("Data piece %d: ", i);
scanf("%f", &data[i]);
printf("\n");
}
}