
Problem passing char * to a function where it is assigned its value
I am trying to pass a char * to a function where upon some processing of
data the value of the pointer is set to the address of an array of char
embedded in a struct. This is on an embedded system, so I have limited
debug capability.
code fragment:(s):
unsigned char *robstr;
do // Get ack message on COM0
{
status = GetMsgCOM0( &robstr );
if( ack_time >= 300 ) timeout = 1;
}while(( status == -1 ) && ( timeout == 0 ));
S_BUFFER com0_msg_buf;
char GetMsgCOM0( char *buffer )
{
// process...
// if success
*buffer = com0_msg_buf.storage;
return;
Quote:
}
where the struct is:
struct small_buffer_type
{
unsigned char storage[256]; /* Buffer storage array */
unsigned char size;
unsigned char in; /* Input index */
unsigned char out; /* Output index */
unsigned char over; /* Buffer overflow flag */
Quote:
};
typedef struct small_buffer_type S_BUFFER;
At the point where GetMsgCOM0 is entered, I sent the value of buffer out the
serial port. It had the address of robstr as its value, which seems right.
The problem comes when I try to assign the value of &com0_msg_buf.storage to
robstr through buffer.
I don't want to alter the character string pointed to by
com0_msg_buf.storage. I just want to access it as though it were an array
without having com0_msg_buf be a global variable.
Do I need to use char ** to pass a pointer to a pointer to char, so I can
assign the address of the pointer?
Please help!
--
Robert Allen
Development Engineer
Electrosonic Systems, Inc.