In my code I have a struc
struct Test {
int a;
int b;
char c;
};
int TestFunction(void* ptr){
struct Test test;
test.a = 0;
test.b = 1;
strcpy(c,"hello");
return 0;
}
struct Test* temp = (struct Test*)ptr;
struct Test test = *temp;
Since you want to be able to modify the struct pointed to, your sample code is not appropriate. What it does is create a local copy of the pointed-to struct and modifies the local copy instead of the original object.
What you want to do, rather, is this:
int TestFunction(void *ptr) {
struct Test *test = ptr;
test->a = 0;
test->b = 1;
return 0;
}
The a->b
syntax is equivalent to (*a).b
, meaning that it refers to whatever test
points to.