I'm trying to create a function that creates an array in size n with random numbers stored inside, I've been trying several option but once i use the array in main, only the first number shows up correctly.
I'm using CodeBlock by the way.
static int *arr;
int i, num;
printf("enter the length of the array: ");
scanf("%d/n", &num);
arr = get_random_arr(num);
for(i=0;i<num;i++)
{
printf("outside the function: %d\n", *(arr+i));
}
return 0;
int *get_random_arr(int num)
{
int temp_arr[num];
int i;
srand((unsigned)time(NULL));
for (i=0;i<num;i++)
{
temp_arr[i] = rand() % 1001 ;
printf("inside the function: %d\n",temp_arr[i]);
}
return temp_arr;
}
and this is the code that compiles:
enter the length of the array: 3 inside the function: 224 inside the function: 774 inside the function: 60 outside the function: 224 outside the function: 2686648 outside the function: 1977872892
Thank's to "coderredoc" his answer was the solution i was looking for