You might have a function that does it:
Code:
void add_position(Position** list, int col, int row)
{
Position* new_position = malloc(sizeof(Position));
new_position->col = col;
new_position->row = row;
// It's easiest to add the new node to the start of the list
// Otherwise you have to walk through the list to find the end and then append the new node there
new_position->next = *list;
*list = new_position;
}
int main(void)
{
Position* positions = NULL;
add_position(&positions, 50, 5);
add_position(&positions, 20, 135);
add_position(&positions, 120, 80);
}
And then you can use any old Position* pointer to start at positions and as long as the pointer isn't NULL, you can print the struct's members and move to the next node:
Code:
Position* p;
for(p = positions;p != NULL;p = p->next)
printf("%d %d\n", p->col, p->row);