I was working on a homework assignment and I can't understand how to return a pointer from a void function. This is what I have below. Can someone help me out or give me a hint at least? Thank you!
typedef struct Node {
void *data;
struct Node *next;
} Node;
/* List: Represents a linked list. */
typedef struct List {
Node *head;
int size;
} List;
* Given: A pointer to a List structure
* Returns: The size of that list */
43 void *lstget(List *lst, int idx) {
42 Node *current = NULL;
43 int count;
44 bool found = false;
45
46 if(lst->head == NULL || idx > lst->size || idx < 0)
47 return NULL;
48 current = lst->head;
49
50 while(!found) {
51 if(count == idx) {
52 bool found = true;
53 /* THIS IS WHERE I WANNA DO IT */
54 }
55 current = current->next;
56 count++;
I was thinking to so something like this, but I am not sure if it would work:
*lst = *((Node *)current->data)