you problem is your re-using the name array each time, so p[0] points to name, p[1] points to name and p[2] points to name.