>Please guide me how can I access the data of a void type buffer?
Normally [B]malloc[/B]
is used in a way like this:
int *p;
p = (int *) malloc( 50 * sizeof( int ) ); // allocate space for 50 integers
As you can see in the example above/below, the void pointer which is returned by malloc is casted to an integer pointer
int *p;
p = [B](int *)[/B] malloc( 50 * sizeof( int ) );
If malloc couldn't allocate the memory, then it returns a NULL-pointer, but using a NULL-pointer will almost certainly crash your whole program, that's why it's generally recommended to check the return value of malloc before using the pointer where you've tried to assign memory to...
Checking whether the allocation has succeeded can be achieved by something like this:
int *p;
p = (int *) malloc( 50 * sizeof( int ) ); // allocate space for 50 integers
if( !p ) {
// out of memory
// the memory could not be allocated
}
BTW, Don't forget to free the allocated memory as well, otherwise you'll have memory leaks in your program :)
Hope this helps!