I have a linked list of 'ball' objects and a function to add new balls to the list. I also have a 'letter' object, which now has its own function to add letters to that objects list. Is there anyway that I could recode this as a generic function to handle any object? It would save a lot of repetitive code.
Code:/***************************************************************/ struct ball { float x, y; float dx, dy; int rad; struct ball *next; }; typedef struct ball ball; ball *NewBall(ball **head) { ball *newnode; if(!(newnode = malloc(sizeof(*newnode)))) return NULL; newnode->next=*head; *head = newnode; return newnode; } /***************************************************************/ struct letter { float x, y; char ch; struct letter *next; }; typedef struct letter letter; letter *NewLetter(letter **head) { letter *newnode; if(!(newnode = malloc(sizeof(*newnode)))) return NULL; newnode->next=*head; *head = newnode; return newnode; } /***************************************************************/