I have an array of structs called arrayOfElements , the structs are called Elements which have a void pointer
typedef struct {
void* data;
} Element;
Ive malloc'd arrayOfElements
Element* arrayOfElements;
arrayOfElements= malloc(4 * sizeof(Element));
and have stored ints and strings in the strucs
arrayOfElements[3].data = malloc( sizeof(int) );
ptr = arrayOfElements[3].data;
*ptr = 65;
strcpy(arrayOfElements[1].data, token );
Then I have created a Linked List
typedef struct LinkedList {
void* arrayOfStruct;
struct LinkedList* next;
} LinkedList;
And have created a function to import a instance of arrayOfELements and make void* arrayOfStruct point to it
LinkedList* insert(LinkedList* head, Element* inArrayOfElements) {
LinkedList* insertNode = malloc(sizeof(LinkedList));
insertNode->next = head;
insertNode->arrayOfStruct = (void*)inArrayOfElements;
return insertNode;
}
Question
My question is after I have pointed void* arrayOfStruc to an instance of arrayOfELements, how do I print void* data of arrayOfElements[3] which I know from before is an int and its value is 65
Current Node in LinkedList ---> arrayOfElements[3] --> data member in Element struct (should equal 65)
I have a feeling I should point a int pointer to it and then print that, but Im not sure the syntax to do it