Originally Posted by
zahid990170
Is there a way in C, to make this act as a class, from which we can create objects, and each one retains its properties.
Yes, altho you don't need to do that, what you have should be fine.
To be clear: you have a function, create_tree(), which returns a pointer to the root node of a tree created from a file. You call that three times, storing the pointer in 3 separate variables.
No problem -- unless there is something wrong with create_tree(). Consider:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *create_txt (char *txt) {
char *rv = malloc(strlen(txt)+1);
strcpy(rv,txt);
return rv;
}
int main(void) {
char *a = create_txt("one"),
*b = create_txt("two"),
*c = create_txt("three");
printf("%s\n%s\n%s\n", a, b, c);
free(a);
free(b);
free(c);
return 0;
}
These pointers retain their value and so should yours.
Post the code for create_tree().