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 3 of 11 Topic 26051 of 26977
Post > Topic >>

Re: problem with realloc

by Barry Schwarz <schwarzb@[EMAIL PROTECTED] > May 3, 2008 at 09:51 PM

On Sat, 3 May 2008 09:33:17 -0700 (PDT), vippstar@[EMAIL PROTECTED]
 wrote:

>On May 3, 7:21 pm, Igal <igal.al...@[EMAIL PROTECTED]
> wrote:
>> hay, i'm doing this program. having problem wiht realloc in the
>> function that reads data structures into array (pointer - bp2), this
>> happens after reading the second record. when call to realloc.
>> i can't figure out what's wrong, think it's soming got to do with
>> freeing bp2.
>> and something called "corruption of the heap".
>>
>> book* LoadBookData(unsigned *size)
>> {
>>         FILE* fp;
>>         int n = 0;
>>         book *bp2 = NULL;
>>
>>         //open book data file
>>         fp=fopen("book.bin","rb");
>>         if (fp == NULL)
>>         {
>>                 bp2 = (book*)calloc(0, sizeof(book));
>>                 return bp2;
>Don't cast calloc. I'm not sure what the results of calloc(0, N) are,
>but if they are similar of malloc(), then that pointer is not really
>reliable.
>You most likely want something like this:
>  return calloc(0, sizeof book);

book is a type.  The parentheses are required.  Other than the cast
and parentheses, your code is identical to the OP's.  Surely not your
intent.



Remove del for email
 




 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 Sat Jul 26 3:45:18 CDT 2008.