Hi all. I am very rusty in C so please bear with me. I want to send a function an array and then return a different array. I understand how to send the array to a function, but not to get it back. Is this the best way of passing arrays from functions by initializing the arrays in the main function?
My error that I ended up is this:
error: expression must be a pointer to a
complete object type
another_array[i][j]=cnt++;
What is wrong with this????
Code:
#include <stdio.h>
#include <stdlib.h>
void function(int array[], int another_array[][]);
int main(void)
{
int i;
int array[10];
int another_array[5][5];
//Create test array
for(i=0;i<10;i++)
{
array[i]=i;
}
function(array,another_array);
for(i=0;i<5;i++)
{
printf("array[%d]=%d\n",i,array[i]);
printf("another_array[%d]=%d\n",i,another_array[i][1]);
}
return 0;
}
void function(int array[], int another_array[][])
{
int i,j,cnt=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
another_array[i][j]=cnt++;
}
}
}
Thank you for your time ^^