I Have a struct, and a constructor method for it. However, I am unable to create initialize the struct properly. In the parameters, I pass a pointer to that struct type, and all its instance variable(sorry for using java terminology, new to C). here is my code for the method.
typedef struct anagramElement anagramElement;
struct anagramElement {
char* word;
char* key;
};
void createAnagramElement(char* const word, char* const key, anagramElement* rv)
{
rv = (anagramElement*) malloc(sizeof(anagramElement));
rv->word = word;
rv->key = key;
}
In the main after, passing anagramElement *ptr, char *Word, char*key, when printing the elements data, segmentation fault occurs. NOTE:I Cannot change the parameters or the method return type.