Passing array back to main function
Hello people :) i'm having problems with my program, what its supposed to do is ask the user how many integers to store, then for every integer it asks the user to store a number at the integer location, for example:
User enters 3 integers to input
- User enters number 4 and is stored in the first integer location
- User enters number 78 and is stored in the second integer location
- User enters number 12 and is stored in the third integer location
Then the program displays the users integers in thier spectified locations example:
4 in integer 1
78 in integer 2
12 in integer 3
However after i put my integers in the program goes crazy and generates a crazy amount of integers before the program seg faults. and i'm not quite sure to to correct this error, any ideas would be helpful.
Code:
#include<stdlib.h>
#include<stdio.h>
void getInts(int * integersArray, int numInput);
int main() {
int * integersArray;
int numInput;
int i;
getInts(integersArray, numInput);
for (i = 0; i < numInput; i++) {
printf("%d ",integersArray[i]);
}
return 0;
}
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);
for (i = 0; i < numInput; i++) {
printf("please enter integer %d: ", i+1);
scanf("%d", &(integersArray[i]));
}
}