Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: problem wit...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 11 Topic 26051 of 26972
Post > Topic >>

Re: problem with realloc

by Igal <igal.alkon@[EMAIL PROTECTED] > May 3, 2008 at 04:53 PM

> 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.
 




 11 Posts in Topic:
problem with realloc
Igal <igal.alkon@[EMAI  2008-05-03 09:21:19 
Re: problem with realloc
vippstar@[EMAIL PROTECTED  2008-05-03 09:33:17 
Re: problem with realloc
Barry Schwarz <schwarz  2008-05-03 21:51:53 
Re: problem with realloc
<brya103@[EMAIL PROTEC  2008-05-03 13:13:32 
Re: problem with realloc
Joe Wright <joewwright  2008-05-03 13:29:04 
Re: problem with realloc
Ulrich Eckhardt <dooms  2008-05-03 19:39:27 
Re: problem with realloc
Igal <igal.alkon@[EMAI  2008-05-03 16:53:18 
Re: problem with realloc
vippstar@[EMAIL PROTECTED  2008-05-03 17:00:05 
Re: problem with realloc
vippstar@[EMAIL PROTECTED  2008-05-04 04:42:39 
Re: problem with realloc
Ulrich Eckhardt <dooms  2008-05-13 15:10:48 
Re: problem with realloc
santosh <santosh.k83@[  2008-05-16 00:22:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:22:10 CDT 2008.