Jun 5, 2012 at 9:03am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#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:
1 2
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
1 2
*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.
Last edited on Jun 5, 2012 at 9:06am UTC
Jun 5, 2012 at 9:22am UTC
Problem is solved:
I should write:
(*ptr)->character='a'
instead of *ptr->character='a'
Last edited on Jun 5, 2012 at 9:22am UTC
Jun 5, 2012 at 9:22am UTC
Try this: ( *ptr) ->character='a' ; // Note ()
Jun 5, 2012 at 9:25am UTC
HINT : Operator -> has a higher precedence than the * operator.