int* dividers_of(int x, int ammount){
int i,j = 1;
int* dividers = (int*)calloc(ammount,sizeof(int)); /* calloc initializes int array to 0!*/
for(i=0;i<ammount;i++){
while( (x%j) != 0){
j++;
}
*(dividers+i) = j;
/*DOESNT WORK ( int* dividers stays on 0-0-0)
*dividers = j;
dividers++; */
j++;
}
return dividers;
}
I'm trying to find out what's wrong with the code that doesn't work, I'm assigning int j
to *dividers
and then making dividers
point to the next int
in its array. The result should be a pointer to an array which contains the int
dividers of an int x
.
Unfortunately the result if i do it like this is the following array:
dividers[] = {0,0,0};
which means nothing has changed since calloc
fills the array like this.
Whats happening at
*dividers = j;
dividers++;
?