I have a function need to pass an array and the array value will be modified in that function. I implement it as follows, but the values in the array does not change after the function is called. Could any one help me with this? Thanks!
This is where I call the function, socket.Receive(sender,buffer,sizeof(buffer)). The variable buffer does not get the right value.
while ( true )
{
Address sender;
unsigned char buffer[256];
int bytes_read = socket.Receive( sender, buffer, sizeof( buffer) );
if ( !bytes_read )
break;
printf("%d\n",buffer[92]);
}
This is the code of function socket.Receive()
int Socket::Receive( Address & sender,
void* data,
int size )
{
unsigned char packet_data[256];
unsigned int max_packet_size =
sizeof( packet_data );
#if PLATFORM == PLATFORM_WINDOWS
typedef int socklen_t;
#endif
sockaddr_in from;
socklen_t fromLength = sizeof( from );
size = recvfrom( handle,
(char*)packet_data,
max_packet_size,
0,
(sockaddr*)&from,
&fromLength );
data = packet_data;
unsigned int from_address = ntohl( from.sin_addr.s_addr );
unsigned int from_port = ntohs( from.sin_port );
return size;
}
packet_data[256]is a local scope variable array, don't you?