Hi, can some one please tell me why this program is not able to function properly. I have a array a and i am trying to create a pointer array b which points to elements less than 40 in a. I got a warning from the compiler:
warning #2116: Local 'b' is used but never assigned a value.
Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void create_ptr_list(int *a, int **b, int n, int *size_ptr)
{
int i;
*size_ptr = 0;
for (i = 0; i < n; i++)
{
if (a[i] < 40)
*size_ptr ++;
}
*b = malloc(sizeof(int *) * (*size_ptr));
*size_ptr = 0;
for (i = 0; i < n; i++)
{
if (a[i] < 40)
b[*size_ptr ++] = &a[i];
}
}
int main(void)
{
int a[] = { 5, -6, 45, -100, 20, -150, 160, 40, 0, 0, 1};
int **b;
int size;
int i;
create_ptr_list(a, b, 10, &size);
for(i = 0; i <size; i++)
printf("%d\n", *b[i]);
return (0);
}