Re: problem passing pointer array
- From: vippstar@xxxxxxxxx
- Date: Mon, 30 Jun 2008 10:00:00 -0700 (PDT)
On Jun 30, 7:51 pm, vipps...@xxxxxxxxx wrote:
On Jun 30, 7:15 pm, pereges <Brol...@xxxxxxxxx> wrote:You also don't check the return value of malloc. It could be NULL, in
On Jun 30, 8:59 pm, vipps...@xxxxxxxxx wrote:
Change int ***b to int **b.
Change the 'int **b' in your main() to int *b.
Wouldn't int *b lead to an array instead of array of pointers ? I
needed array of pointers hence int **b.
Sorry, I just realized that.
The problem in your original code is in this line:> (*b)[*size_ptr++]= &a[i];
that increments 'size_ptr' as a pointer, not the value it points to.
Change it to (*b)[(*size_ptr)++] = &a[i];
which case you just return; the caller can check for the
successfulness of create_ptr_list(a, &b, c, &d); with if(b !=
NULL) ...
Also the design is flawed, mainly because this works only for arrays
of ints, and because 40 is hardcoded, how about you change this to
struct vector { size_t nmemb, size; void *elements; };
struct vector *remove_if(const struct vector *v, int (*remove)(void
*));
though I don't like the 'remove_if' name, I chose it because there's a
similar function in common lisp named REMOVE-IF.
.
- Follow-Ups:
- Re: problem passing pointer array
- From: pereges
- Re: problem passing pointer array
- References:
- problem passing pointer array
- From: pereges
- Re: problem passing pointer array
- From: vippstar
- Re: problem passing pointer array
- From: pereges
- Re: problem passing pointer array
- From: vippstar
- problem passing pointer array
- Prev by Date: Re: problem passing pointer array
- Next by Date: Re: Runtime stack allocation
- Previous by thread: Re: problem passing pointer array
- Next by thread: Re: problem passing pointer array
- Index(es):
Relevant Pages
|