Accessing inside a structure via using a struct pointer to a struct pointer

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 ptrinside function function but I couldn't find a way to do this.
Last edited on
Problem is solved:

I should write:
(*ptr)->character='a'

instead of *ptr->character='a'
Last edited on
Try this: (*ptr)->character='a'; // Note ()
HINT : Operator -> has a higher precedence than the * operator.
Topic archived. No new replies allowed.