On May 4, 2:53 am, Igal <igal.al...@[EMAIL PROTECTED]
> wrote:
> > If `bp2' doesn't point to a pointer returned by realloc, malloc or
> > calloc, realloc() will produce undefined results (unless `bp2's value
> > is NULL)
> > But I *see* what you are trying to do, here's the actual logic:
> > size_t n = 0;
> > back:
> > if(fread(&bp2[n], sizeof bp2[0], 1, fp) != 1) { /* handle error or EOF
> > */ }
> > n++;
> > bp2 = realloc(bp2, n+1 * sizeof bp2[0]);
> > if(bp2 == NULL) { /* ... */ }
> > goto back;
>
> thanks, this helped a lot. i just didn't know i can use bp2 just as
> normal array.
Depends, in this case you can.
Read section 6 of the FAQ <http://c-faq.com/>
which explains arrays/
pointers and then read the rest of the FAQ.


|