Hi,
I'm new to C as well. Sorry if my suggestion turns out to be wrong.
As far as I understand, for a function to return an array it should be declared as returning a pointer to a desired type, in your code to a type int. (e.g int * func(void))
The return statement should be something like (return array). The name of an array is a pointer to the 1st element of an array.
It probably defies the purpose of your task, but you may want to consider the following code:
Code:
#include <stdio.h>
#define SIZE 3
/* function prototype; ar[] being a pointer to type int;
* n being array size */
void func(int ar[], int n);
int main(void)
{
int i; /* counter variable */
/* declare an array of 3 ints */
int array[SIZE];
/* call func() to initialise array[]; pass array name, itself a pointer and
* an array size */
func(array, SIZE);
/* print contents of array */
for (i = 0; i < SIZE; i++)
printf("%d ", array[i]);
printf("\n");
return 0;
}
void func(int ar[], int n)
{
int i;
for (i = 0; i < n; i++)
ar[i] = i + 5; /* any other numbers desired */
}
You may also want to see this link for an answer to how to return arrays from functions.