problem passing pointer array
- From: pereges <Broli00@xxxxxxxxx>
- Date: Mon, 30 Jun 2008 08:33:29 -0700 (PDT)
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.
#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);
}
.
- Follow-Ups:
- Re: problem passing pointer array
- From: pete
- Re: problem passing pointer array
- From: vippstar
- Re: problem passing pointer array
- Prev by Date: Re: how to release memory?
- Next by Date: Re: Pedants
- Previous by thread: Re: OFF TOPIC:Censorship By Google Groups Of My Post About Gordon Sauck Being A Police Agent
- Next by thread: Re: problem passing pointer array
- Index(es):