On 17 Mar, 18:01, "Plisske...@gmail.com" <Plisske...@gmail.comwrote:
>
typedef struct {
char* buffer;
int len;
} buffer_t;
static buffer_t* buffer[BUFSIZE];
And I want to implement a function which set the input pointer, points
to the first element of buffer.
int getItem(buffer_t** itemp) {
*itemp = &(buffer[0]);
return 1;
}
I can't get the following code to work,
main() {
buffer_t* p;
getItem(p);
// p should points to buffer[0] after return from getItem(),
}
You'll need to call getItem( &p );
and getItem should read:
*itemp = buffer[0]; (&buffer[0] is
a buffer_t **, so for the assignment
*itemp = &buffer[0] to be meaningful, itemp
would have to be of type buffer_t ***.)
Two stylistic points:
1. rather than &buffer[0],why not just say "*itemp = buffer;"?
2. Why the typedef? just define the struct, and use it:
struct buff {
char *buffer;
size_t length;
};
int getItem( struct buff **itemp )
{
*itemp = buffer[0];
....
IMO, using the typedef is unnecessary obfuscation.
--
Bill Pursell