> My problem is now solved with using calloc
It would be more correct to say your problem has been side-stepped by using calloc
calloc is more expensive than malloc, and comes with a health warning
You should really find out where you're doing something like this say
Code:
char *p = malloc( 100 );
strcat( p, "hello" ); // bad code, *p is uninitialised
Where it would have been much better to do this
Code:
char *p = malloc( 100 );
*p = '\0'; // an empty string
strcat( p, "hello" ); // good code, *p is initialised
However, perhaps you really meant to
Code:
char *p = malloc( 100 );
strcpy( p, "hello" ); // good code, *p is initialised by copy
Now sometimes you do want to clear the whole array, and calloc is the correct thing to do. If you're just after an empty string, then calloc is very expensive compared to just initialising the first byte to 0.
> Even if I pass the buffer an empty file
Perhaps you're using while ( !feof() ) in your code