Can someone tell me how the heck to get input into an array of pointers, via my code.
insert
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int granularity, *Arrayptr,iLoop,iCount,iarray;
char *arraysize;
char szBuf[10];
printf("Input the array size: \n"); //Ask the user for input
arraysize = fgets(szBuf,sizeof(szBuf), stdin); //Get the input from the user
iarray = atoi(arraysize); //Convert Input from string to integer
Arrayptr = malloc(iarray * sizeof(int)); //Reserve some memory on the heap for the array
if((Arrayptr = malloc(iarray * sizeof(int))) == NULL){
(void)printf("Malloc failed");
return 1;
}
if(Arrayptr != NULL){
printf("Please input values into array -1 to quit: \n");
for(iLoop = 0 ;; iLoop ++){
scanf("%d",Arrayptr[iLoop]);
iCount += Arrayptr[iLoop];
}
}
return 0;
}
I'm trying to use scanf but it's not working, then I want to take the value entered and keep a running total, I'm just not sure why it's not working.
Thanks
Andrew