You reassign integersArray inside getInts, so it no longer refers to the value submitted from main:
Code:
void getInts(int * integersArray, int numInput) {
int i;
printf("Please enter the number of integers you want to input\n");
scanf("%d", &numInput);
integersArray = (int *) malloc(sizeof(int) * numInput);
That's the same as doing this:
Code:
#include <stdio.h>
void test(int x) {
x = 42;
}
int main(int argc, const char *argv[]) {
int n = 666;
test(n);
printf("%d\n",n);
return 0;
}
"n" still equals 666. If you wanted to modify the value at the address of n in test (so that it equalled 42 in main), you'd do this:
Code:
test(int *x); // prototype
test(&n); // call
A parallel to what you are doing is:
Code:
void getInts(int ** integersArray, int numInput);
getInts(&integersArray, numInput);
"integersArray" is still a pointer, so this is called a pointer to a pointer. Then inside the function, you dereference:
Code:
*integersArray = (int *) malloc(sizeof(int) * numInput);