I am trying to build a function that gets (**group, *count)
where count is the amount of items in the array and the group is a pointer to the array.
I must use **group
instead of the much easier *group
.
Edit: as requested ive included my main()
func:
int *group1, **pgroup1, count1 = 0, *pcount1;
pgroup1 = &group1;
printf("please enter what size do you want the array to be..\n");
scanf("%d", &count1);
pcount1 = &count1;
BuildGroup(pgroup1, pcount1);
void BuildGroup(int** group, int* count)
{
int i = 0, j = 0, c = *count;
group = (int**)malloc(c*sizeof(int**));
if (group == NULL)
{
printf("ERROR: Out of memory\n");
return 1;
}
printf("please enter the %d items in the array...\n", *count);
for (i = 0; i < *count; i++) //going through the array items to be filled.
{
scanf("%d", &group[i]);
for (j = 0; j < i; j++)
{
while (group[i] == group[j]) //checking every item if he is already in the group,if he is in the group prompting the user for re-entering.
{
printf("you've entered the same value as beforehand, please enter this value again..\n");
scanf("%d", &group[j]);
}
}
}
}
I don't know why but malloc
doesn't allocate the memory needed for the array. On the other hand, it doesn't trigger the if (==null)
so I really don't know what I am doing wrong.