You have two problems here:
The pointer receiveddata
is uninitialized and is thus pointing to some random location in memory. This will cause you to trash data somewhere.
The change that you make to the buffer
pointer is not passed on to the outside. If you want to do this, you have to use a double pointer.
Here's a solution to both of these problems:
void doSomething(unsigned char **buffer)
{
unsigned char* receiveddata;
// Allocate memory
// Note: You need to know the maximum length of data that you will
// ever receive here.
receiveddata=new unsigned char[MAXIMUM_NUMBER_OF_CHARS_YOU_WILL_RECEIVE];
Socket.recv(receiveddata);
*buffer = receiveddata;
printout(buffer);
}
Note that this code is vulnerable to a buffer overflow attack in case someone can send it more data than you expect. What sockets library are you using? Does it have a mechanism that can protect you from writing more data to the buffer than it can take (for example, an additional argument to recv specifying the length of the buffer)?
You would call this as follows:
unsigned char* buffer;
doSomething(&buffer);
// Process the data in buffer, then free it when you're done:
delete [] buffer;
However, as others have pointed out, it's cumbersome to have to manage memory allocation and deletion yourself. Take a look at the standard library and the string and collection classes contained in it -- those can make life easier and safer by doing the memory management for you.
Edited as noted in the comments.