Im trying to write a program that asks the user for the size of an array and if they are asked again then the size of the array would increase based on the number they input.
int main()
{
int size;
int n;
printf("Size of array: ");
scanf("%d", &n);
int *ptr = (int*)malloc(n*sizeof(int));
size = n;
int n1;
do {
printf("Input the increase size of the array: ");
scanf("%d", &n1);
size += n1;
int *ptr = realloc((size)*sizeof(int));
} while (n1 != -1);
return 0;
}
Here is what I have got but how can I move this into a function