I am working on a school project which fills integers arrays with random numbers then sorts them and records the times. I've gotten the sorting functions to work but I'm running into an issue when making the arrays. The project instructions tell us to declare the array with:
int * array = (int *) malloc (arraySizes[i] * sizeof(int));
arraySizes is an array with the lengths of the arrays we are making in them i.e. [1000, 2000, 3000]
When I run the program it does make a random number with the fill function but no matter the data size, the array is initialized with a length of 8. Is there anything I am doing wrong with my array initialization?
Attached below is the function that initializes the array and the function that fills the array with random numbers. The main function is just used for picking between int arrays and string arrays, which I have a group partner working on string arrays.
void Int_Arrays(){
//printf("Size Trial[0] Trial[1] Trial[2] Trial[3] Trial[4] Average\n");
Node *head = NULL; // for storing times
int i;
int j;
int m;
for(j = 0; j < numTrials; j++){
int dataSize;
dataSize = arraySizes[j];
printf("DataSize: %d\n", dataSize);// for debugging
int * array = (int *) malloc (arraySizes[j] * sizeof(int));
printf("Inital array size: %d\n", sizeof(array));// for debugging
printf("%d ", arraySizes[j]);
fillArray_int(array, arraySizes[j]);
int n = sizeof(array)/sizeof(array[0]);
//printf("array size: %d\n", sizeof(array));
for (i = 0; i < sizeof(array); i++){
printf("%d ", array[i]);
}
printf("\n");
for (m = 1; m <= 5; m++){
//runSort_Int(array, n); // runs sorting functions
}
double avg = avgTime(head); // calculates time averages
// printf(" %lf", &avg);
// printf("\n");
free(array);
}
}
void fillArray_int(int arr[], int dataSize)
{
printf("Data Size: %d\n", dataSize); // for debugging
printf("array size: %d\n", sizeof(arr)); // for debugging
int i = 0;
srand(time(0));
while (i < dataSize)
{
arr[i] = 0;
int r = (randNum()% 9) + 1;
arr[i] = r;
i++;
}
}