|
-
June 5th, 2012, 03:51 AM
#1
Accessing inside structure via a struct pointer to a struct pointer
"
#include <stdio.h>
struct datastructure
{
char character;
};
void function(struct datastructure** ptr);
int main()
{
struct datastructure trial;
struct datastructure *structPtr;
structPtr=&trial;
structPtr->character='a';
function(&structPtr);
}
void function(struct datastructure** ptr)
{
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
}
"
These codes give these errors:
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
these errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"
I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.
-
June 5th, 2012, 04:10 AM
#2
Re: Accessing inside structure via a struct pointer to a struct pointer
You should have written:
Code:
(*ptr)->character = 'a';
Otherwise, the compiler interprets it as *(ptr->character), but of course a pointer does not have a character member.
-
June 5th, 2012, 04:20 AM
#3
Re: Accessing inside structure via a struct pointer to a struct pointer
Thank you very much,really I was working on it for hours to make it work!
-
June 5th, 2012, 04:22 AM
#4
Re: Accessing inside structure via a struct pointer to a struct pointer
You're welcome 
That said, why do you need to pass a pointer to a pointer? You are not modifying the pointer to the struct object, so just passing a pointer to the struct object will do.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|