In the later snippet at the later part,
head -> city -> name
is wrong, because, city
is not a pointer type. You need to use the dot operator (.
) to access a member of a non-pointer structure variable. Just the way you've used it in
head -> next ->city.name
Other than that, syntactically, the snippets appear fine.
Just to add, as a basic sanity, you should be checking for non-NULL
-ity of a pointer before de-referencing to avoid invoking undefined behavior.