Hi there,
i've ran in a problem and made up an example code of my prob.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct mystruct
{
int a;
}mytype;
mytype* createMytype(int x)
{
mytype *mt;
mt = (mytype*)calloc(1, sizeof(mytype));
mt->a = x;
return mt;
}
int foo(mytype* mt)
{
mt = createMytype(6);
return 0;
}
int bar(mytype* mt)
{
printf("%p\n", mt->a);
return 0;
}
int main(int argc, const char **argv)
{
mytype *mt;
mt = (mytype*)calloc(1, sizeof(mytype*));
foo(mt);
bar(mt);
exit(0);
}
The problem is, after leaving the foo-scope the struct is set to null.
Can somebody explain my fault?
Thx in advance