what is the method to return an array to main? I know the array is created but cant return it, so when I try to use it is says "incompatible types in assignment"?
int* get_array(){
int i = 0, j;
int *array = malloc(6);
srand(time(NULL));
while (i != 6)
{
int random_number = ((rand() % 49) + 1);
int ok = 1;
for (j = 0 ; ok && j != i ; j++)
{
ok &= (random_number != array[j]);
}
if (ok)
{
array[i++] = random_number;
}
}
return array;
}
then call it from the main:-
int main()
{
int i;
int* get_lotto_numbers();
int numbers[6];
numbers = get_lotto_numbers();
for(i = 0; i < 6; i++)
{
printf("%d ", numbers[i]);
}
}
any comments will help thanks.
get_arrayandget_lotto_numbers- did you modify your example?malloc(6 * sizeof(int))rather thanmalloc(6). The latter will only allocate 6 bytes.